时间段查询
获取本周整个时间段
SELECT TRUNC(SYSDATE,'iw') - 1 + ROWNUM FROM DUAL CONNECT BY ROWNUM <= 7
获取上周整个时间段
SELECT TRUNC(SYSDATE,'iw') - 8 + ROWNUM FROM DUAL CONNECT BY ROWNUM <= 7
获取本月整个时间段
SELECT TRUNC(SYSDATE, 'mm') - 1 + ROWNUM FROM DUAL CONNECT BY ROWNUM <= TO_CHAR(LAST_DAY(SYSDATE),'dd')
获取上月整个时间段
SELECT TRUNC(ADD_MONTHS(SYSDATE, -1), 'month') - 1 + ROWNUM FROM DUAL CONNECT BY ROWNUM <= TO_CHAR(LAST_DAY(TRUNC(ADD_MONTHS(SYSDATE, -1), 'month')),'dd')
获取最近7、30、90天的整个时间段
SELECT TRUNC(SYSDATE, 'dd') - ROWNUM AS day FROM DUAL CONNECT BY ROWNUM <= 7 (可自行设置)
时间点查询
获取本周一时间
SELECT TRUNC(SYSDATE, 'iw') FROM DUAL
获取本周末时间
SELECT TRUNC(SYSDATE, 'iw') + 6 FROM DUAL
获取上周一时间
SELECT TRUNC(SYSDATE, 'iw') - 7 FROM DUAL
获取上周末时间
SELECT TRUNC(SYSDATE, 'iw') - 1 FROM DUAL
获取本月的第一天
SELECT TRUNC(SYSDATE, 'mm') FROM DUAL
获取本月的最后一天
SELECT TRUNC(ADD_MONTHS(SYSDATE, -1), 'month') FROM DUAL
7、30、90天前时间
SELECT SYSDATE - 7 FROM DUAL (可自行调节)
SELECT SYSDATE - 30 FROM DUAL (可自行调节)
SELECT SYSDATE - 90 FROM DUAL (可自行调节)