mysql中怎么查询一天24小时的数据量

因为业务需求我也是查了百度,有给出一些sql,我现在再总结一下
我这里是比较两个时间,所以会使用到两个sql
mysql中查询一天中每一个小时的记录数量

select count(*) as orderCounts from ec_order o WHERE o.order_type=1
AND o.order_time  >= str_to_date('2018-04-11 00:00:00','%Y-%m-%d %T')    
 AND o.order_time < str_to_date('2018-04-11 23:59:59','%Y-%m-%d %T')    
group by HOUR(o.order_time)

select count(*) as payCounts from ec_order o WHERE 
o.order_type=1 and o.order_status=1 and o.pay_status=1
AND o.pay_time  >= str_to_date('2018-04-11 00:00:00','%Y-%m-%d %T')    
 AND o.pay_time < str_to_date('2018-04-11 23:59:59','%Y-%m-%d %T')    
group by HOUR(o.order_time)

应该很郁闷,这里为什么使用一个时间进行分组,是因为这里是进行比较,比较就需要有一个共同的点才能进行比较,不然就没有意义,所以这里都根据一个时间进行分组

mysql查询一天中每半个小时记录的数量

SELECT HOUR(e.time)as Hour,FLOOR(MINUTE(e.time)/30) as M, COUNT(*) as Count 
FROM error_log e 
WHERE e.date = '2017-09-02' 
GROUP BY FLOOR(MINUTE(e.time)/30),HOUR(e.time) 
ORDER BY Hour(e.time);

你可能感兴趣的:(mysql)