
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
您可能感兴趣的文章:
解析mysql中:单表distinct、多表group by查询去除重复记录mysql分组取每组前几条记录(排名) 附group by与order by的研究MySQL高级查询之与Group By集合使用介绍mysql中group by与having合用注意事项分享使用GROUP BY的时候如何统计记录条数 COUNT(*) DISTINCT关于MYSQL中每个用户取1条记录的三种写法(group by xxx)mysql筛选GROUP BY多个字段组合时的用法分享MySql版本问题sql_mode=only_full_group_by的完美解决方案详解SQL中Group By的用法一篇文章带你了解数据库中group by的用法