oracle中如何按小时 oracle时间加1小时
Oracle数据按小时分组的语句
创建测试表,随便弄了点数据:
我们注重客户提出的每个要求,我们充分考虑每一个细节,我们积极的做好成都网站建设、成都网站设计服务,我们努力开拓更好的视野,通过不懈的努力,创新互联建站赢得了业内的良好声誉,这一切,也不断的激励着我们更好的服务客户。 主要业务:网站建设,网站制作,网站设计,微信小程序,网站开发,技术开发实力,DIV+CSS,PHP及ASP,ASP.Net,SQL数据库的技术开发工程师。
create table test
(timestamp date);
insert into test values (to_date('2017-12-7 9:00:00','yyyy-mm-dd hh24:mi:ss'));
insert into test values (to_date('2017-12-7 9:01:00','yyyy-mm-dd hh24:mi:ss'));
insert into test values (to_date('2017-12-7 11:00:00','yyyy-mm-dd hh24:mi:ss'));
insert into test values (to_date('2017-12-7 11:20:00','yyyy-mm-dd hh24:mi:ss'));
insert into test values (to_date('2017-12-7 11:30:00','yyyy-mm-dd hh24:mi:ss'));
commit;
执行:
select to_char(timestamp,'yyyy-mm-dd hh24')||':00:00',count(*) from test group by to_char(timestamp,'yyyy-mm-dd hh24')||':00:00'
结果:
只针对时间字段为date类型有效,其他类型的话需要改语句。
oracle按小时分组查询
select
decode(tl, '00:00——00:30', to_char(a-1,'yyyymmdd'), to_char(a,'yyyymmdd')) as 天,
decode(tl, '00:00——00:30', '16:31——00:30', '16:31——00:00', '16:31——00:30', t1) as 时间段,
sum(b)
from
(
select
a,
case
when to_char(a, 'hhmi') ='0030' then '00:00——00:30'
when to_char(a, 'hhmi') between '0031' and '0830' then '00:30——08:30'
when to_char(a, 'hhmi') between '0031' and '1630' then '00:31——16:30'
when to_char(a, 'hhmi') = '1631' then '16:31——00:00'
else ''
end as tl,
b
from table_name
)
group by
decode(tl, '00:00——00:30', to_char(a-1,'yyyymmdd'), to_char(a,'yyyymmdd')),
decode(tl, '00:00——00:30', '16:31——00:30', '16:31——00:00', '16:31——00:30', t1)
oracle中怎么按每小时分组。数据如下:
select time,count(time) from (
select substr('2014-01-01 20:03:00',1,13) as time from table_name) group by time;
网站名称:oracle中如何按小时 oracle时间加1小时
标题网址:http://cdiso.cn/article/hgsodg.html