Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
COUNT DISTINCT with condition
Message
From
22/04/2014 14:17:56
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Desktop
Miscellaneous
Thread ID:
01598897
Message ID:
01598902
Views:
46
>>I have a SQL Query that counts the number of employees in the query.
>>
>>COUNT(Distinct paEmKey) AS EmployeesCount
>>
>>I also need another count, but that would be based on a condition of another field.
>>So if I were to use a case statement it would look like, but that obviously cannot work.
>>
>>CASE Balance <> 0.00 THEN COUNT(Distinct paEmKey) ELSE 0 END AS EmployeesCountWithBalances
>>
>>I thought perhaps a subquery, but maybe there is a better way?
>
>
>SELECT count(distinct(case when Balance <> 0 then paEmKey END)) as DistinctCountClientsWithBalance from ...
Thanks, but unfortunately the result is just a count without the distinct.
Christian Isberner
Software Consultant
Previous
Reply
Map
View

Click here to load this message in the networking platform