0

ID POST_ID

1 60
2 457
3 457
4 457
5 25
6 25

我如何获得投票最多的列表,结果将是:

457
25
60

4

2 回答 2

5
  SELECT post_id 
    FROM my_table 
GROUP BY post_id 
ORDER BY COUNT(id) DESC
于 2010-12-05T22:52:32.083 回答
3
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         |
+---------+-----------+
于 2010-12-05T22:55:07.003 回答