欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

深入解析mysql中order by与group by的顺序问题

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


来自 
http://www.jb51.net/article/38950.htm
普通分类: