Oracle以15分钟为界,统计一天内各时间段的数据笔数。
Oracle以15分钟为界,统计一天内各时间段的数据笔数。DTIMEV1V2-----------------------------2010092910:22:1320...
Oracle以15分钟为界,统计一天内各时间段的数据笔数。
DTIME V1 V2
----------------- ------ ------
20100929 10:22:13 200 200
20100929 10:32:13 200 200
20100929 15:32:06 200 200
20100929 15:42:06 200 200
20100929 16:22:00 300 300
20100929 16:32:00 200 300
20100929 17:01:51 100 100
20100929 17:11:51 100 100
20100929 17:51:45 100 100
20100929 18:01:45 100 100
20100929 18:21:33 0 100
20100929 18:31:33 100 100
这该如何汇总出来呢?只统计各个时间片段内,出现的记录条数。 展开
DTIME V1 V2
----------------- ------ ------
20100929 10:22:13 200 200
20100929 10:32:13 200 200
20100929 15:32:06 200 200
20100929 15:42:06 200 200
20100929 16:22:00 300 300
20100929 16:32:00 200 300
20100929 17:01:51 100 100
20100929 17:11:51 100 100
20100929 17:51:45 100 100
20100929 18:01:45 100 100
20100929 18:21:33 0 100
20100929 18:31:33 100 100
这该如何汇总出来呢?只统计各个时间片段内,出现的记录条数。 展开
2个回答
展开全部
我试了下,楼上的做法是可行的,我稍微优化了下,看起来清晰一点。
select count(*),
(case floor((to_char(db_time,'mi'))/15)
when 0 then to_char(db_time,'yyyy.mm.dd hh')||':00:00'
when 1 then to_char(db_time,'yyyy.mm.dd hh')||':15:00'
when 2 then to_char(db_time,'yyyy.mm.dd hh')||':30:00'
when 3 then to_char(db_time,'yyyy.mm.dd hh')||':45:00'
end) as db_time
from table
group by db_time
select count(*),
(case floor((to_char(db_time,'mi'))/15)
when 0 then to_char(db_time,'yyyy.mm.dd hh')||':00:00'
when 1 then to_char(db_time,'yyyy.mm.dd hh')||':15:00'
when 2 then to_char(db_time,'yyyy.mm.dd hh')||':30:00'
when 3 then to_char(db_time,'yyyy.mm.dd hh')||':45:00'
end) as db_time
from table
group by db_time
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这么难得题目都不给点分!试试把,看可不可以!
SELECT count(*),
CASE FLOOR((TO_CHAR(DTIME,'MI'))/15)
WHEN 0 THEN TO_CHAR(DTIME,'YYYYMMDDHH')||'0000'
WHEN 1 THEN TO_CHAR(DTIME,'YYYYMMDDHH')||'1500'
WHEN 2 THEN TO_CHAR(DTIME,'YYYYMMDDHH')||'3000'
WHEN 3 THEN TO_CHAR(DTIME,'YYYYMMDDHH')||'4500'
END as D_TIME
FROM TABLE
GROUP BY D_TIME
SELECT count(*),
CASE FLOOR((TO_CHAR(DTIME,'MI'))/15)
WHEN 0 THEN TO_CHAR(DTIME,'YYYYMMDDHH')||'0000'
WHEN 1 THEN TO_CHAR(DTIME,'YYYYMMDDHH')||'1500'
WHEN 2 THEN TO_CHAR(DTIME,'YYYYMMDDHH')||'3000'
WHEN 3 THEN TO_CHAR(DTIME,'YYYYMMDDHH')||'4500'
END as D_TIME
FROM TABLE
GROUP BY D_TIME
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询