重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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(*) "字段条数"
创新互联公司主营新都网站建设的网络公司,主营网站建设方案,成都APP应用开发,新都h5重庆小程序开发搭建,新都网站营销推广欢迎新都等地区企业咨询
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;
假设你的表为 ta 日期字段是 dt
那么,以 2015-01-01为起始日,每5天累总计数为:
select datediff(dt, '2015-01-01') div 5 as d5 , count(*)
from ta
group by (datediff(dt, '2015-01-01') div 5)
select DATE_FORMAT(来电时间,'%Y-%m') as 月, 问题类别 , count(1) as 数量 from
( select 来电时间, 问题类别 from mytable where 问题类别 = '农村用水投诉' ) tmptable
group by DATE_FORMAT(来电时间,'%Y-%m') ,问题类别 ORDER BY 月 ASC;
时间段统计,可以采用 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