select to_char((trunc(sysdate)+trunc((
日期-trunc(sysdate))*24)/24),'hh24') ||'-'||to_char((trunc(sysdate)+trunc((日期-trunc(sysdate))*24+1)/24),'hh24')
时间段, avg(统计
字段平均值),sum(统计字段和),count(*) "字段条数"from 表名where trunc(日期)=to_date(&day,'yyyymmdd') group by to_char((trunc(sysdate)+trunc((日期-trunc(sysdate))*24)/24),'hh24')||'-'|| to_char((trunc(sysdate)+trunc((日期-trunc(sysdate))*24+1)/24),'hh24') order by 1时间段统计,可以采用 hour(subscribe_time) 取出小时然后分层。思路:
select
uid
,CASE WHEN HOUR(subscribe_time) BETWEEN 0 AND 1 THEN '00:00:00'
WHEN HOUR(subscribe_time) BETWEEN 2 AND 3 THEN '02:00:00'
...
ELSE '23:00:00' END -- 生成时间分层部分,insert前外层sql加上日期后作为唯一的时间值
,COUNT(*)
FROM yht_fans WHERE subscribe_time>=UNIX_TIMESTAMP(CURDATE()) and subscribe_time<=UNIX_TIMESTAMP(CURDATE())+86400
GROUP BY 1,2
评论列表(0条)