[Oracle/오라클] ROLLUP 소계 / 총계 표현하기
SELECT * FROM TB_POINT; SELECT NVL(CUSTOMER_CD,'총합') AS customer_cd, TO_CHAR(SUM(POINT),'999,999') AS 포인트합 FROM TB_POINT GROUP BY ROLLUP(CUSTOMER_CD) ORDER BY customer_cd; SELECT NVL(CUSTOMER_CD, '소계') 고객번호, TO_CHAR(SUM(POINT), '999,999') 포인트합, COUNT(*) 인원 FROM TB_POINT GROUP BY ROLLUP(CUSTOMER_CD); SELECT NVL(SALES_DT, '총합') AS SALES_DT, CASE WHEN SALES_DT IS NOT NULL AND PRODUCT_NM IS NULL THE..
2021. 7. 16.
[Oracle/오라클] ADD_MONTHS, MONTH_BETWEEN
ADD_MONTHS 지정일 기준 개월 수 추가또는 감소 계산 SELECT SYSDATE, ADD_MONTHS(SYSDATE, -3) AS "3_BF_MON", ADD_MONTHS(SYSDATE, 5) AS "5_AF_MON" FROM DUAL; MONTH_BETWEEN 기간을 월 기준으로 계산 SELECT SYSDATE, ADD_MONTHS(SYSDATE, -3) AS "3_BF_MON", ROUND(MONTHS_BETWEEN(ADD_MONTHS(SYSDATE, -3), SYSDATE), 2) MONTH_TERM, TO_DATE('20220408', 'YYYYMMDD') AS "STR_DATE", ROUND(MONTHS_BETWEEN(TO_DATE('20220408', 'YYYYMMDD'), SYSDAT..
2021. 7. 11.