mysql 简单查询语句

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;

 

posted @ 2017-05-11 10:42  一壶烧开的水  阅读(192)  评论(0)    收藏  举报