oracle 取某個時間段的數據,具體代碼如下所示:
select count(*),t.分組字段 from (select t.* ,to_char(t.時間,'HH24') stime,to_char(t.時間,'HH24mi') fz,to_char(時間,'d') from A twhere 時間>=to_date('2019-12-01','yyyy-MM-dd') and ghsj<=to_date('2019-12-31','yyyy-MM-dd') and to_char(時間,'d')='2') where stime in ('08','09','10','11','12') and fz>=0800 a group by T.分組字段to_char(時間,'d') 取當前時間是星期幾 每星期第一天為周日to_char(t.時間,'HH24mi') 取當前時間的小時分o_char(t.時間,'HH24') 取當前時間的小時
ps:oracle 同一個數據有多條記錄,根據條件取時間最大的那一條
1.第一種方式
select max(t1.INVALID_TIME) from T_CUSTOMER t1 where t1.customer_code = '5101'
1.第二種方式
SELECT INVALID_TIME FROM (SELECT * FROM T_CUSTOMER WHERE customer_code='5101' ORDER BY INVALID_TIME desc) WHERE ROWNUM =1
1.第三種方式
select INVALID_TIME from T_CUSTOMER t where INVALID_TIME=(select max(INVALID_TIME) from T_CUSTOMER where customer_code='5101') and ROWNUM =1
5.不過濾存在多條最大時間
select INVALID_TIME from T_CUSTOMER t wheret.INVALID_TIME = (select max(t1.INVALID_TIME) from T_CUSTOMER t1 where t1.customer_code = '5101')
總結
以上所述是小編給大家介紹的oracle 取某個時間段的數據(每周幾的上午幾點到幾點),希望對大家有所幫助!
新聞熱點
疑難解答