trante
trante

Reputation: 34006

MYSQL query for summing occurence of some column

Let's say I have such MYSQL table for logins:

id---name---location---login_date
----------------------------------
1----mike----usa-----21.08.2012
2----tony----uk------22.08.2012
3----tony----uk------23.08.2012
4----david--france---24.08.2012
5----mike----usa-----25.08.2012
6----tony----uk------26.08.2012
7----ash--france----27.08.2012

I need this output. Results will be GROUPed BY name, ORDERED BY login_times.
What would be the fastest query for this situation?

login_times---name
3-------------tony
2-------------mike
1-------------david
1-------------ash

Upvotes: 0

Views: 64

Answers (1)

Felix
Felix

Reputation: 812

SELECT COUNT(*) AS 'login_times', name 
FROM logins 
GROUP BY name 
ORDER BY login_times DESC

http://sqlfiddle.com/#!2/6e176/9

But whathaveyoutried.com?

Upvotes: 3

Related Questions