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
时间: 2024-10-10 13:28:45