oracle关于数据库 时间统计的查询问题

oracle关于数据库 时间统计的查询问题,第1张

这种情况下,你需要特殊处理下出差日期和回日期。我简单写了一下,你参考下。

with t as (

select 'a' name, '2014-6-20' go_date, '2014-6-30' end_date, 11 totalday from dual

union all

select 'a' name, '2014-5-28' go_date, '2014-6-3' end_date, 6 totalday from dual

union all

select 'a' name, '2014-6-28' go_date, '2014-7-3' end_date, 6 totalday from dual

union all

select 'a' name, '2014-5-29' go_date, '2014-7-2' end_date, 4 totalday from dual

union all

select 'b' name, '2014-5-29' go_date, '2014-7-2' end_date, 34 totalday from dual)

select name, sum(edate-gdate+1) from

(select name, case when to_date(go_date, 'yyyy-mm-dd') < to_date('2014-6-1', 'yyyy-mm-dd') then to_date('2014-6-1', 'yyyy-mm-dd')

else to_date(go_date, 'yyyy-mm-dd') end gdate,

case when to_date(end_date, 'yyyy-mm-dd') > to_date('2014-6-30', 'yyyy-mm-dd') then to_date('2014-6-30', 'yyyy-mm-dd')

else to_date(end_date, 'yyyy-mm-dd') end edate

from t)

group by name;

使用sql语句查询:

select from table1 t where tTime between to_date('2007-03-03 18:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2007-09-04 18:00:00','yyyy-mm-dd hh24:mi:ss')

用to_char函数即可。

如emp表中数据如下:

要查询hiredate的日期为1981年1月1日到1981年5月1日之间的数据,可用如下语句:

1

select

from

emp

where

to_char(hiredate,'yyyy-mm-dd')

between

'1981-01-01'

and

'1981-05-01';

查询结果:

以上就是关于oracle关于数据库 时间统计的查询问题全部的内容,包括:oracle关于数据库 时间统计的查询问题、oracle数据库中,如何查询指定时间段内的记录、在oracle中怎么查看在某一段时间内执行的sql语句所用的时间等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9871768.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-02
下一篇2023-05-02

发表评论

登录后才能评论

评论列表(0条)

    保存