获取每天的每个小时的某个字段总值
例 获取一天订单的每个小时的销售总额(做折线图)
sql语句 :
select from_unixtime(p.order_time, '%h') time, sum(money) money
from pay_order as p
where from_unixtime(p.order_time, '%Y-%m-%d') = from_unixtime(unix_timestamp(now()),'%Y-%m-%d')
group by from_unixtime(p.order_time,'%h');
from_unixtime 格式化时间戳
unix_timestamp 将日期转成时间戳
group by 分组
语句意思就是 查询出当天的所有订单,然后按小时分组