Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
COUNT DISTINCT with condition
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Desktop
Divers
Thread ID:
01598897
Message ID:
01598898
Vues:
67
This message has been marked as the solution to the initial question of the thread.
>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 ...
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform