首页 > 代码库 > mysql 简单查询语句

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;

 

mysql 简单查询语句