oracle 取某个时间段的数据,具体代码如下所示:
select count(*),t.分组字段 from (
select t.* ,to_char(t.时间,"HH24") stime,to_char(t.时间,"HH24mi") fz,to_char(时间,"d")
from A t
where 时间>=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 取某个时间段的数据(每周几的上午几点到几点),希望对大家有所帮助!