mysql count以DESC顺序返回多行

时间:2015-05-11 19:22:50

标签: mysql sql

我有读取计数只返回一行,但是如果你使用group by你可以得到多行返回

enter image description here

返回上述结果的代码是

  

SELECT event_id,COUNT(event_id)AS nr FROM picks GROUP BY   event_id DESC LIMIT 0,30

但是我现在需要找到一种按DESC顺序订购它的方法。我已经尝试了order by,但后来只返回1行,看起来我不能将DESC与group by一起使用。寻求建议

更新

以下是给我的结果,如下图所示

SELECT event_id, COUNT( event_id ) AS nr
FROM  picks
GROUP BY event_id
Order by event_id DESC
LIMIT 0 , 30

enter image description here

1 个答案:

答案 0 :(得分:0)

降序

SELECT event_id, COUNT( event_id ) AS nr
FROM  picks
GROUP BY event_id
Order by event_id DESC
LIMIT 0 , 30

enter image description here

升序 //这是默认的排序顺序

SELECT event_id, COUNT( event_id ) AS nr
FROM  picks
GROUP BY event_id
Order by event_id
LIMIT 0 , 30

enter image description here