
正文
oracle中如何按小时 oracle 小时加减
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Oracle按半小时分组的sql
想到一个办法,不过还要再套一层才行。
利用case when将原表稍作改动,就是类似case when to_char(时间,'mi')30 then 'A' else 'B' end 分段字段
这样就会出现一个新字段,字段是由A或B组成的,然后分组的时候,用时间(到小时,就是你的‘YYYY-mm-dd HH24‘)+AB分段字段 组合分组,这样就是半小时一分组了。
相关问答
Q1: oracle中怎么按每小时分组。数据如下:
select time,count(time) from (
select substr('2014-01-01 20:03:00',1,13) as time from table_name) group by time;
Q2: Oracle数据按小时分组的语句
创建测试表oracle中如何按小时,随便弄oracle中如何按小时了点数据oracle中如何按小时:
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;
执行oracle中如何按小时:
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中如何按小时他类型的话需要改语句。
Q3: oracle 中什么函数可以把分钟显示为多少小时 多少分钟的格式
如果只想用oracle内置的函数,那么只有这个,把数字转换成interval类型,显示结果分4段,天、小时、分钟、秒。
下例把100分钟显示成1小时40分钟:
SQL select NUMTODSINTERVAL(100,'MINUTE') from dual;
NUMTODSINTERVAL(100,'MINUTE')
---------------------------------------
+000000000 01:40:00.000000000
如果不想用内置函数(因为超过24小时会自动转换成1天),可以自己写函数,算法如下
下例把100分钟显示成1小时40分钟:
SQL select floor(100/60) HOURS,mod(100,60) MINUTES from dual;
HOURS MINUTES
---------- ----------
1 40
SQL
Q4: 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中如何按小时和oracle 小时加减的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






