Home >Database >Mysql Tutorial >深入解析mysql中order by与group by的顺序问题_MySQL

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

WBOY
WBOYOriginal
2016-06-01 13:24:591270browse

bitsCN.com 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 descbitsCN.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn