问题背景:
想把数据分组、排序查询,于是就想到先group by 然后 order by,但是不知怎么使用,
于是查资料发现group by 与order by 一起使用有一些注意事项。
注意事项:
1.order by 的列,必须是出现在group by 子句里的列
2.order by 要 放在 group by的 后面
样例
select borrowmonth,count(borrowmonth) as sum_borrow from peak_time
group by borrowmonth
order by borrowmonth desc;