創(chuàng)建測試表,隨便弄了點(diǎn)數(shù)據(jù):
我們注重客戶提出的每個(gè)要求,我們充分考慮每一個(gè)細(xì)節(jié),我們積極的做好成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)服務(wù),我們努力開拓更好的視野,通過不懈的努力,創(chuàng)新互聯(lián)建站贏得了業(yè)內(nèi)的良好聲譽(yù),這一切,也不斷的激勵(lì)著我們更好的服務(wù)客戶。 主要業(yè)務(wù):網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)站設(shè)計(jì),微信小程序,網(wǎng)站開發(fā),技術(shù)開發(fā)實(shí)力,DIV+CSS,PHP及ASP,ASP.Net,SQL數(shù)據(jù)庫的技術(shù)開發(fā)工程師。
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;
執(zhí)行:
select?to_char(timestamp,'yyyy-mm-dd?hh24')||':00:00',count(*)?from?test?group?by?to_char(timestamp,'yyyy-mm-dd?hh24')||':00:00'
結(jié)果:
只針對時(shí)間字段為date類型有效,其他類型的話需要改語句。
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 時(shí)間段,
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)
select time,count(time) from (
select substr('2014-01-01 20:03:00',1,13) as time from table_name) group by time;