當前位置:首頁 » 編程語言 » oraclesql查詢時間段

oraclesql查詢時間段

發布時間: 2025-02-28 16:34:15

① oracle sql語句中怎麼查詢一個月內固定時間段的數據,比如9月1號到10月1號每天的八點到九點的呼叫數目

使用Oracle 函數extract(fmt from d)獲取日期中的特定部分:
select count(*) from table where
SQL> select * from table where createdate
between to_date('2010-9-1','yyyy-MM-dd') and to_date('2010-10-1','yyyy-MM-dd')
and EXTRACT(hour from createdate) between '8:00' and '9:00';

② oracle資料庫 查詢時間段一年的數據的SQL語句怎麼寫。 比如查詢一年白班時間(八點至五點)的數據

使用to_char()將時間欄位轉換成字元串然後再做。例如
select * from table1
where to_char(t,'HH24')>=8 and to_char(t,'HH24')<17

③ oracle 查詢一段時間內每一天的統計數據sql怎麼寫

可以寫一個簡單的procere來實現,原理是遍歷日期范圍,並查詢日期資料筆數,寫入表。
數據源表test03
1 2016-06-01 1
2 2016-06-02 1
3 2016-06-05 1
4 2016-06-04 1
5 2016-06-04 1

procere代碼如下:
create or replace procere loop_by_date(pbeg_tim in varchar2,--開始日期
pend_tim in varchar2,--結束日期
errmessage out varchar2) is

nCount number(10); --總天數
i_point number(10); --當天
is_zero number(10); --當天是否有記錄
begin
nCount := 0;
i_point := 0;
is_zero := 0;

select ROUND(to_date(pend_tim, 'yyyy-mm-dd') -
to_date(pbeg_tim, 'yyyy-mm-dd'))
into nCount
from al;

delete from test02;

<<fst_loop>>
loop

select count(*)
into is_zero
from test03
where date1 =
to_char(to_date(pbeg_tim, 'yyyy-mm-dd') + i_point, 'yyyy-mm-dd');

insert into test02
(date01, nccount)
values
(to_char(to_date(pbeg_tim, 'yyyy-mm-dd') + i_point, 'yyyy-mm-dd'),
is_zero);

i_point := i_point + 1;
exit fst_loop when i_point >= nCount;
end loop fst_loop;
--end;

end loop_by_date;

傳入參數"2016-06-01"~~"2016-06-10"並執行,結果寫入test02為:
1 2016-06-01 1
2 2016-06-02 1
3 2016-06-03 0
4 2016-06-04 2
5 2016-06-05 1
6 2016-06-06 0
7 2016-06-07 0
8 2016-06-08 0
9 2016-06-09 0

④ sql 查詢某欄位的某段內容

如果 表結構是這樣的話 text ,sdate 的話 可以使用
select test||sdate from book where sdate = (select min(sdate) from book where text ='張三')

熱點內容
伺服器光口配ip 發布:2025-09-19 05:48:37 瀏覽:844
phpmongodb擴展 發布:2025-09-19 05:35:23 瀏覽:775
停資料庫監聽 發布:2025-09-19 05:35:14 瀏覽:44
裸車後需要什麼配置 發布:2025-09-19 05:34:38 瀏覽:185
軟體資源碼 發布:2025-09-19 05:33:58 瀏覽:43
c語言中文編譯器怎麼安裝 發布:2025-09-19 05:33:57 瀏覽:14
啟辰t90的配置怎麼樣 發布:2025-09-19 04:58:54 瀏覽:490
水密碼洗面奶在哪裡買 發布:2025-09-19 04:58:45 瀏覽:97
拒絕訪問本緩存伺服器管理員 發布:2025-09-19 04:53:21 瀏覽:917
java01隨機 發布:2025-09-19 04:53:13 瀏覽:226