oracle 取某個(gè)時(shí)間段的數(shù)據(jù),具體代碼如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
|
select count (*),t.分組字段 from ( select t.* ,to_char(t.時(shí)間, 'HH24' ) stime,to_char(t.時(shí)間, 'HH24mi' ) fz,to_char(時(shí)間, 'd' ) from A t where 時(shí)間>=to_date( '2019-12-01' , 'yyyy-MM-dd' ) and ghsj<=to_date( '2019-12-31' , 'yyyy-MM-dd' ) and to_char(時(shí)間, 'd' )= '2' ) where stime in ( '08' , '09' , '10' , '11' , '12' ) and fz>=0800 a group by T.分組字段 to_char(時(shí)間, 'd' ) 取當(dāng)前時(shí)間是星期幾 每星期第一天為周日 to_char(t.時(shí)間, 'HH24mi' ) 取當(dāng)前時(shí)間的小時(shí)分 o_char(t.時(shí)間, 'HH24' ) 取當(dāng)前時(shí)間的小時(shí) |
ps:oracle 同一個(gè)數(shù)據(jù)有多條記錄,根據(jù)條件取時(shí)間最大的那一條
1.第一種方式
1
|
select max (t1.INVALID_TIME) from T_CUSTOMER t1 where t1.customer_code = '5101' |
1.第二種方式
1
|
SELECT INVALID_TIME FROM ( SELECT * FROM T_CUSTOMER WHERE customer_code= '5101' ORDER BY INVALID_TIME desc ) WHERE ROWNUM =1 |
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.不過濾存在多條最大時(shí)間
1
|
select INVALID_TIME from T_CUSTOMER t wheret.INVALID_TIME = ( select max (t1.INVALID_TIME) from T_CUSTOMER t1 where t1.customer_code = '5101' ) |
總結(jié)
以上所述是小編給大家介紹的oracle 取某個(gè)時(shí)間段的數(shù)據(jù)(每周幾的上午幾點(diǎn)到幾點(diǎn)),希望對大家有所幫助!
原文鏈接:https://www.cnblogs.com/chenxiaoyao/archive/2020/01/03/12145813.html