The order of order by and group by in mysql is deeply analyzed


The order of order by and group by in mysql is: select from where group by order by Note: group by executes before order by. order by does not sort group by internally. If there is only one record after group by, then order by will be invalid. The max or min functions are used to find the largest or smallest of the 1 fields in group by. Ex. : 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