Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
COUNT(*) with GROUP BY
Message
De
29/01/2017 14:55:04
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
COUNT(*) with GROUP BY
Versions des environnements
SQL Server:
SQL Server 2014
OS:
Windows 8.1
Network:
Windows Server 2012
Divers
Thread ID:
01647119
Message ID:
01647119
Vues:
42
A select like this will return all the uniques values of NoMember:
SELECT Client.NoMember
 FROM Client
 WHERE Client.Active=1
 GROUP BY Client.NoMember
Now, let's assume the goal is to obtain the count.

The following would not work:
SELECT COUNT(*) AS RecordCount
 FROM Client
 WHERE Client.Active=1
 GROUP BY Client.NoMember
...as it will return all records related to the group and that the GROUP BY itself.

In my example, I have 19 records for the same member. So, the first select returns one record saying that Client.NoMember found is 1. The second select returns a count of 19.

What would be the best approach to count over the group by? Basically, I would like to obtain 1 as all those 19 records are from the same member.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform