創(chuàng)建測試表,隨便弄了點數(shù)據(jù):
我們注重客戶提出的每個要求,我們充分考慮每一個細節(jié),我們積極的做好成都網(wǎng)站建設、成都網(wǎng)站設計服務,我們努力開拓更好的視野,通過不懈的努力,創(chuàng)新互聯(lián)建站贏得了業(yè)內(nèi)的良好聲譽,這一切,也不斷的激勵著我們更好的服務客戶。 主要業(yè)務:網(wǎng)站建設,網(wǎng)站制作,網(wǎng)站設計,微信小程序,網(wǎng)站開發(fā),技術開發(fā)實力,DIV+CSS,PHP及ASP,ASP.Net,SQL數(shù)據(jù)庫的技術開發(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'
結果:
只針對時間字段為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 時間段,
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;
新聞標題:oracle中如何按小時 oracle時間加1小時
URL分享:http://chinadenli.net/article16/hgsodg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供建站公司、移動網(wǎng)站建設、網(wǎng)站排名、動態(tài)網(wǎng)站、網(wǎng)站建設、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)