SQL - 按列分组,然后按“计数”结果排序

时间:2013-06-19 22:43:00

标签: mysql sql group-by

我的意思是Title是这样的:说我有100行。一列是review_id。然后,我想要Group By review_id。然后,我想count每组行,然后Sort By

示例结果:20行review_id 132,17行review_id 434行,8行review_id 22 - (这是按降序排序)

我该怎么做?以下是参与的球员:

列中名为votereview_id的表格。它与一个名为reviews的表结合,review_id作为其唯一键。

2 个答案:

答案 0 :(得分:1)

SELECT COUNT(a.review_id) as total, a.review_id
FROM vote a
INNER JOIN reviews b
ON a.review_id = b.review_id
GROUP BY a.review_id
ORDER BY total ASC

答案 1 :(得分:0)

select 
    count(vote.review_id) 
from vote, review
where
    vote.review_id = review.review_id
group by
    vote.review_id