Exitos
Exitos

Reputation: 29720

How do I count the similar entries in a table?

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

Answers (3)

vice
vice

Reputation: 605

SELECT companyid, count(companyid) as TotalEntries
FROM YourTable
GROUP BY companyid

Upvotes: 1

Adam Wenger
Adam Wenger

Reputation: 17560

SELECT t.CompanyId, COUNT(1)
FROM schema.table AS t
GROUP BY t.CompanyId

Upvotes: 2

Joe Stefanelli
Joe Stefanelli

Reputation: 135848

SELECT companyid, COUNT(*) AS CompanyCount
    FROM YourTable
    GROUP BY companyid

Upvotes: 3

Related Questions