I do not know what to name this problem. Correct me if you have better words.
I have two tables, users and posts.
Users
id | username | password | ...
Posts:
id | author_id | title | content | ...
Now I want to list the "most active" users - the users who wrote most of the posts. And specifically, I want a top 10 result.
SELECT u.username, COUNT(p.id) AS count FROM Posts p, Users u WHERE u.id=p.author_id GROUP BY p.author_id ORDER BY count DESC LIMIT 10;
I can get the expected result. However, the rating cannot be “fair” if some users have the same number of posts.
For example, I can get results such as:
User 1 | 14 User 2 | 13 ... User 9 | 4 User 10 | 4
There are several more users who have 4 posts.
So top 10 may not be exactly 10 . How can I get a more “fair” result that contains additional rows of users who have 4 posts?
sql mysql select sql-order-by limit
mrmoment
source share