Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
COUNT(*) with GROUP BY
Message
From
29/01/2017 14:55:04
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
COUNT(*) with GROUP BY
Environment versions
SQL Server:
SQL Server 2014
OS:
Windows 8.1
Network:
Windows Server 2012
Miscellaneous
Thread ID:
01647119
Message ID:
01647119
Views:
41
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
Next
Reply
Map
View

Click here to load this message in the networking platform