ID POST_ID
1 60
2 457
3 457
4 457
5 25
6 25
我如何获得投票最多的列表,结果将是:
457
25
60
SELECT post_id
FROM my_table
GROUP BY post_id
ORDER BY COUNT(id) DESC
SELECT post_id, count(post_id) num_votes
FROM your_table
GROUP BY post_id
ORDER BY num_votes DESC
会给你:
+---------+-----------+
| post_id | num_votes |
+---------+-----------+
| 457 | 3 |
| 25 | 2 |
| 60 | 1 |
+---------+-----------+