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 THEN '<소계>'
WHEN PRODUCT_NM IS NULL THEN '---------------'
ELSE PRODUCT_NM
END AS PRODUCT_NM,
SUM(PRICE * SALES_COUNT) AS 매출금액
FROM TB_SALES
GROUP BY ROLLUP(SALES_DT, PRODUCT_NM)
ORDER BY SALES_DT;
1
2
3
4
5
6
7
8
9
10
11
12
|
SELECT NVL(SALES_DT, '총합') AS SALES_DT,
CASE
WHEN SALES_DT IS NOT NULL AND PRODUCT_NM IS NULL THEN '<소계>'
WHEN PRODUCT_NM IS NULL THEN '---------------'
ELSE PRODUCT_NM
END AS PRODUCT_NM,
SUM(PRICE * SALES_COUNT) AS 매출금액
FROM TB_SALES GROUP
BY ROLLUP(SALES_DT, PRODUCT_NM)
ORDER BY SALES_DT;
|
cs |
'스터디 > Oracle' 카테고리의 다른 글
[Oracle/오라클] 다중 LIKE 조건 REGEXP_LIKE (0) | 2021.07.17 |
---|---|
[Oracle/오라클] LSITAGG (0) | 2021.07.16 |
[Oracle/오라클] ADD_MONTHS, MONTH_BETWEEN (0) | 2021.07.11 |
[Oracle/오라클] LAST_DAY 월의 마지막 날 구하기 (0) | 2021.07.11 |
[Oracle / 오라클] Sub Query 서브쿼리 예제 (0) | 2021.05.31 |