深入解析mysql中order by與group by的順序問題
更新時間:2013年06月23日 21:44:40 作者:
本篇文章是對mysql中order by與group by的順序問題進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
mysql 中order by 與group by的順序是:
select
from
where
group by
order by
注意:group by 比order by先執(zhí)行,order by不會對group by 內(nèi)部進(jìn)行排序,如果group by后只有一條記錄,那么order by 將無效。要查出group by中最大的或最小的某一字段使用 max或min函數(shù)。
例:
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
select
from
where
group by
order by
注意:group by 比order by先執(zhí)行,order by不會對group by 內(nèi)部進(jìn)行排序,如果group by后只有一條記錄,那么order by 將無效。要查出group by中最大的或最小的某一字段使用 max或min函數(shù)。
例:
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
您可能感興趣的文章:
相關(guān)文章
阿里云安裝mysql數(shù)據(jù)庫出現(xiàn)2002錯誤解決辦法
這篇文章主要介紹了阿里云安裝mysql數(shù)據(jù)庫出現(xiàn)2002錯誤解決辦法,需要的朋友可以參考下2017-04-04MySQL同步數(shù)據(jù)Replication的實(shí)現(xiàn)步驟
本文主要介紹了MySQL同步數(shù)據(jù)Replication的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03