Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Count Distinct

I would like to count the number of installations of each Member in a table similar to this. But this count distinct drives me nuts...

MemberID | InstallDate

1 | Yesterday

2 | Today

1 | Today

3 | Today

The above table should produce something like this one..

MemberID | CountNumberOfInstallations

1 | 2

2 | 1

3 | 1

p.s. I know it sound's like homework, but it isnt.

like image 573
OrElse Avatar asked Sep 02 '09 07:09

OrElse


1 Answers

It looks like the query you are looking for is:

SELECT MemberID, COUNT(*)
FROM Table
GROUP BY MemberID

The DISTINCT keyword is not required. If order is required, you can use:

SELECT MemberID, COUNT(*)
FROM Table
GROUP BY MemberID
ORDER BY MemberID ASC
like image 53
Roee Adler Avatar answered Sep 28 '22 01:09

Roee Adler