Avv
Avv

Reputation: 519

Get Groups of Customers Names based on their Title

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.

Upvotes: 0

Views: 141

Answers (1)

Reut Schremer
Reut Schremer

Reputation: 368

You can use

SELECT ContactTitle, ContactName, Count(ContactTitle) over (partition by ContactTitle) as usersCoun FROM Customers;

Upvotes: 1

Related Questions