Home > database >  Get Groups of Customers Names based on their Title
Get Groups of Customers Names based on their Title

Time:03-30

Get the Count of Contact's person by their title. (Table: Customers) below:

enter image description here

Now, below SQL code will get group counts, but I want to add also the names associated with each group if possible please:

SELECT ContactTitle, Count(ContactTitle) FROM Customers
GROUP BY ContactTitle;

Database: This is from NorthWind database.

CodePudding user response:

You can use

SELECT ContactTitle, ContactName, Count(ContactTitle) over (partition by ContactTitle) as usersCoun FROM Customers;
  •  Tags:  
  • sql
  • Related