0

我想从 6 月(2017 年 6 月 1 日至 6 月 30 日)的 Oracle 表中选择一些数据,开始日期将从明天(9 月 13 日)开始。因此我用以下格式写了一个查询,

select * from table where column1='Data1' and Column2='Data2'
and trunc(DateTime) between trunc(sysdate-104) and trunc(sysdate-75)

我无法检查此查询,因为我没有用于此的工具。我只是在记事本上写的,想分享给我的朋友。

我的问题 -trunc(DateTime) between trunc(sysdate-104) and trunc(sysdate-75)条件会在 June1st 到 June31 之间提供数据还是那里有任何语法问题?

4

3 回答 3

0

只需将日期格式转换为月/年并与之进行比较。

select *
from table
where column1 = 'Data1'
and column2 = 'Data2'
and to_char(DateTime, 'MMYYYY') = '062017';
于 2017-09-12T18:09:12.927 回答
0

即使您的公式对时间敏感,语法本身也没有问题,这意味着明天它不会返回相同的结果。

相反,请使用以下内容:

AND TRUNC(DateTime) BETWEEN to_date('2016-06-01','YYYY-MM-DD')  
                        AND to_date('2016-06-30','YYYY-MM-DD') 
于 2017-09-12T18:10:46.600 回答
-1

嗨,我认为最准确的是:

select * from table where column1='Data1' and Column2='Data2'
    AND DateTime BETWEEN TRUNC(sysdate-104) 
                 AND TRUNC(sysdate-75) 
                 + interval '23' hour 
                 + interval '59' minute 
                 + interval '59' second;
于 2017-09-12T19:19:31.417 回答