如果我想显示使用滞后条件的双重小于 sysdate 的所有日期,我该怎么做
从项目中选择sysdate - 如何在此查询中使用滞后?
我的输出应使用滞后条件
显示小于 sysdate 的所有日期Date
30-jun-2015
29-june-2015
28-june-2015
等
答案 0 :(得分:0)
查询1 - 选择从开始日期到今天的日期:
SELECT TRUNC(SYSDATE) - LEVEL + 1 AS "Date"
FROM DUAL
CONNECT BY TRUNC(SYSDATE) - LEVEL + 1 >= DATE '2015-06-26'
<强>结果:
| Date |
|------------------------|
| July, 01 2015 00:00:00 |
| June, 31 2015 00:00:00 |
| June, 30 2015 00:00:00 |
| June, 29 2015 00:00:00 |
| June, 28 2015 00:00:00 |
| June, 27 2015 00:00:00 |
| June, 26 2015 00:00:00 |
查询2 - 选择多个范围之间的日期:
WITH ranges ( start_date, end_date ) AS (
SELECT DATE '2015-06-02', DATE '2015-06-07' FROM DUAL
UNION ALL
SELECT DATE '2015-06-12', DATE '2015-06-14' FROM DUAL
)
SELECT START_DATE + COLUMN_VALUE AS "Date"
FROM ranges,
TABLE( CAST ( MULTISET(
SELECT LEVEL - 1
FROM DUAL
CONNECT BY START_DATE + LEVEL - 1 <= END_DATE
) AS SYS.ODCINUMBERLIST ) )
<强>结果:
| Date |
|------------------------|
| June, 02 2015 00:00:00 |
| June, 03 2015 00:00:00 |
| June, 04 2015 00:00:00 |
| June, 05 2015 00:00:00 |
| June, 06 2015 00:00:00 |
| June, 07 2015 00:00:00 |
| June, 12 2015 00:00:00 |
| June, 13 2015 00:00:00 |
| June, 14 2015 00:00:00 |