0

I have a usage database that i use to store some info whenever a user logs in.

So for each login the following is stored

  • rid (auto integer)
  • id (auto integer from the users database where the users details are stored login, contact details ect.)
  • username
  • password
  • date (y-m-d)

Is there a way to count the number of times that a duplicate id appears in the database and ORDER by DESC.

What I want is to tell who is the most active user by counting how many times the same id appears in the database.

1
  • use Group by to count Commented Oct 3, 2014 at 7:12

3 Answers 3

0

Try this query (as Tal Gleicher provided an errorous one, good thinking though):

SELECT id, COUNT(*) as login_count FROM `tbl` 
GROUP BY id 
ORDER BY login_count DESC 

You can set a limit for that query, for example if you want to get top 10 most active users' ids:

SELECT id, COUNT(*) as login_count FROM `tbl` 
GROUP BY id 
ORDER BY login_count DESC 
LIMIT 0, 10
Sign up to request clarification or add additional context in comments.

Comments

0
SELECT id ,COUNT(*) 
FROM usageTable
GROUP BY id 
ORDER BY COUNT(*) DESC;

This will display a list:

id | COUNT(*)

10 | 203
2 | 100
5 | 83

Comments

-1
mysql -> SELECT count(rid) FROM `tbl` ORDER BY rid DESC GROUP BY id

It will show you the number of activities for each id

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.