十大计数使用Mysql Query

时间:2010-09-02 12:19:25

标签: mysql group-by sql-order-by

我正在使用以下mysql查询来分组referrersource。

SELECT referrersource,count(referrersource) as counts 
FROM request_events  
where referrersource!='' 
AND landingpage_collectionid=1 
group by referrersource

在这里,我想按结果集按升序排序。如何更改我的上述查询。请提供任何建议

4 个答案:

答案 0 :(得分:1)

添加ORDER BY counts DESC

答案 1 :(得分:1)

 SELECT referrersource,count(referrersource) as counts 
 FROM request_events  
 where referrersource!='' 
 AND landingpage_collectionid=1 
 group by referrersource
 ORDER BY 2

答案 2 :(得分:0)

添加ORDER BY子句。

SELECT  referrersource
        ,count(referrersource) as counts 
FROM    request_events 
where   referrersource!='' 
        AND landingpage_collectionid=1 
group by 
        referrersource
order by
        2        

答案 3 :(得分:0)

只需添加ORDER BY子句,例如

ORDER BY count(referrersource)