oracle如何取某个时间段
更新:HHH   时间:2023-1-7


这篇文章将为大家详细讲解有关oracle如何取某个时间段,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

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如何取某个时间段”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

返回数据库教程...