當前位置:首頁 » 編程語言 » 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 ='張三')

熱點內容
c語言打開網頁 發布:2025-07-15 05:21:33 瀏覽:640
如何製作我的世界模組伺服器 發布:2025-07-15 05:21:33 瀏覽:903
phparray加 發布:2025-07-15 05:20:41 瀏覽:782
4000以內二手安卓機怎麼選 發布:2025-07-15 05:11:25 瀏覽:644
靜態編譯修復器 發布:2025-07-15 05:11:24 瀏覽:506
iphonexr的存儲空間 發布:2025-07-15 05:09:20 瀏覽:328
能緩存航海王 發布:2025-07-15 04:55:38 瀏覽:90
安卓手機投屏為什麼只能本地視頻 發布:2025-07-15 04:51:19 瀏覽:537
棧的存儲結構 發布:2025-07-15 04:51:16 瀏覽:234
現在天龍八部腳本 發布:2025-07-15 04:45:35 瀏覽:333