oracle sql 获取本季度所有月份,上季度所有月份

上季度所有月份:

SELECT TO_CHAR(ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'YYYY'),A * 3),-ROWNUM),'YYYYMM')  LAST_Q  
    FROM (SELECT TO_CHAR(SYSDATE,'Q')-1 A FROM DUAL)  
    CONNECT BY ROWNUM <= 3  
    ORDER BY 1;  

 

本季度所有月份:

 SELECT TO_CHAR(ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'YYYY'),A * 3),-ROWNUM),'YYYYMM')  LAST_Q  
    FROM (SELECT TO_CHAR(SYSDATE,'Q') A FROM DUAL)  
    CONNECT BY ROWNUM <= 3  
    ORDER BY 1;  

 

posted @ 2018-08-10 16:15  一枚程序员  阅读(6711)  评论(0编辑  收藏  举报