Reputation: 29720
I have a table which has the following data
companyid subscriptionid
1 21
1 23
2 89
4 99
4 101
I want to count how many times each unique company appears, how do I do this using t-sql?
So for example I want to see 1 = 2 times...but I dont mind if its in a table I dont need to print the data....
Upvotes: 0
Views: 95
Reputation: 605
SELECT companyid, count(companyid) as TotalEntries
FROM YourTable
GROUP BY companyid
Upvotes: 1
Reputation: 17560
SELECT t.CompanyId, COUNT(1)
FROM schema.table AS t
GROUP BY t.CompanyId
Upvotes: 2
Reputation: 135848
SELECT companyid, COUNT(*) AS CompanyCount
FROM YourTable
GROUP BY companyid
Upvotes: 3