mysql 中order by 與group by的順序是:
select
from
where
group by
order by
注意:group by 比order by先執行,order by不會對group by 內部進行排序,如果group by後只有一條記錄,那麼order by 將無效。要查出group by中最大的或最小的某一字段使用 max或min函數。
例:
select sum(click_num) as totalnum,max(update_time) as update_time,count(*) as totalarticle from article_detail where userid =1 group by userid order by update_time desc