1、根据小时分组
select DATE_FORMAT(Y_CDATETIME,‘%Y%m%d %H‘) HOUR,count(*) as ‘总量‘ FROM orderdata WHERE Y_CDATETIME >=‘2017-04-27‘ and Y_CDATETIME < ‘2017-04-28‘ GROUP BY HOUR;
2、根据查询结果降序排列
SELECT * FROM( select DATE_FORMAT(Y_CDATETIME,‘%Y%m%d %H‘) HOUR,count(*) as ‘AA‘ FROM orderdata GROUP BY HOUR ) t ORDER BY t.AA DESC;
时间: 2024-10-10 05:52:27