Selecting COUNT(*) with DISTINCT

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Selecting COUNT(*) with DISTINCT

Message par ForumBot »

Selecting COUNT(*) with DISTINCT
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Selecting COUNT(*) with DISTINCT

Message par ForumBot »

Count all the DISTINCT program names by program type and push number

```
SELECT program_type AS [Type],
Count(DISTINCT program_name) AS [Count],
FROM cm_production
WHERE push_number = @push_number
GROUP BY program_type

```

`DISTINCT COUNT(*)` will return a row for each unique count. What you want is [`COUNT(DISTINCT )`](http://msdn.microsoft.com/en-us/library/ms175997.aspx): evaluates expression for each row in a group and returns the number of unique, non-null values.
Répondre

Revenir à « SQL Server »