我想从6月的Oracle表(2017年6月1日至6月30日)中选择很少的数据,开始日期从明天(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,还是会出现语法问题?
发布于 2017-09-12 18:10:46
语法本身没有问题,即使您的公式是时间敏感的,这意味着明天它将不会返回相同的结果。
相反,可以这样做:
AND TRUNC(DateTime) BETWEEN to_date('2016-06-01','YYYY-MM-DD')
AND to_date('2016-06-30','YYYY-MM-DD') 发布于 2017-09-12 18:09:12
只需将日期格式转换为月/年,并与之进行比较。
select *
from table
where column1 = 'Data1'
and column2 = 'Data2'
and to_char(DateTime, 'MMYYYY') = '062017';发布于 2017-09-12 19:19:31
嗨,我想最准确的是:
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;https://stackoverflow.com/questions/46182647
复制相似问题