Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Group by and Count
Message
From
13/09/2021 17:47:33
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Group by and Count
Miscellaneous
Thread ID:
01682285
Message ID:
01682285
Views:
80
I have a SQL which contains some group by with a count :
SELECT MAX(Program.Name) AS Program,MAX(Something.Name) AS Something,COUNT(*) AS 'Count of projects'
 FROM MainTable
 INNER JOIN Program ON MainTable.NoProgram=Program.ID
 INNER JOIN Something ON MainTable.NoSomething=Something.ID
 INNER JOIN Project ON MainTable.ID=Projet.NoMainTable
 GROUP BY Program.Name,Something.Name
Thus, I have my repartition on the first two fields followed by the count of projects corresponding to each record.

Now, I need to add another count. This one is based on the unique count of providers within the 'Count of projects'. Thus, if I have 17 projects, this may be within 5 providers.

I understand I may need to add a subquery somewhere to make that fit. Any suggestion on the best practice?
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