by 기리 [Oracle 기초] group by rollup 중복제거 공백 0 [2018.10.01 17:06:47]
with data as ( SELECT A.IN_DATE IN_DATE, C.HCUST_NAME CUST_NAME, B.MAT_NAME MAT_NAME, SUM(A.IN_QTY) IN_QTY, TRUNC(AVG(A.IN_UPRICE),0) IN_UPRICE, SUM(A.IN_AMT) IN_AMT FROM A, B, C WHERE A.MAT_CODE = B.MAT_CODE AND A.CUST_CODE = C.CUST_CODE AND A.COM_ID = 'D' AND A.IN_DATE BETWEEN '20180901' AND '20180905' AND length(trim(A.mat_code)) = 5 AND decode(trim(A.mat_code),'17101',1,'40101',1,A.in_qty) <> 0 GROUP BY A.IN_DATE, C.HCUST_NAME, B.MAT_NAME ORDER BY A.IN_DATE, C.HCUST_NAME, B.MAT_NAME ) select IN_DATE, CUST_NAME, IN_QTY, IN_UPRICE, IN_AMT, sum(IN_QTY) IN_QTY_s, sum(IN_UPRICE) IN_UPRICE_s, sum(IN_AMT) IN_AMT_s from data group by rollup(IN_DATE, CUST_NAME, IN_QTY, IN_UPRICE, IN_AMT)
아래는 결과값입니다.
IN_DATE | CUST_NAME | IN_QTY | IN_UPRICE | IN_AMT | IN_QTY_s | IN_UPRICE_s | IN_AMT_s |
2018-09-03 0:00 | a업체 | 88 | 5740 | 505120 | 88 | 5740 | 505120 |
2018-09-03 0:00 | a업체 | 88 | 5740 | 88 | 5740 | 505120 | |
2018-09-03 0:00 | a업체 | 88 | 88 | 5740 | 505120 | ||
2018-09-03 0:00 | a업체 | 771 | 5720 | 4410120 | 771 | 5720 | 4410120 |
2018-09-03 0:00 | a업체 | 771 | 5720 | 771 | 5720 | 4410120 | |
2018-09-03 0:00 | a업체 | 771 | 771 | 5720 | 4410120 | ||
2018-09-03 0:00 | a업체 | 859 | 11460 | 4915240 | |||
2018-09-03 0:00 | b업체 | 4737 | 0 | 0 | 4737 | 0 | 0 |
2018-09-03 0:00 | b업체 | 4737 | 0 | 4737 | 0 | 0 | |
2018-09-03 0:00 | b업체 | 4737 | 4737 | 0 | 0 | ||
2018-09-03 0:00 | b업체 | 4737 | 0 | 0 | |||
2018-09-03 0:00 | c업체 | 639 | 5580 | 3565620 | 639 | 5580 | 3565620 |
2018-09-03 0:00 | c업체 | 639 | 5580 | 639 | 5580 | 3565620 | |
2018-09-03 0:00 | c업체 | 639 | 639 | 5580 | 3565620 | ||
2018-09-03 0:00 | c업체 | 1871 | 5580 | 10440180 | 1871 | 5580 | 10440180 |
2018-09-03 0:00 | c업체 | 1871 | 5580 | 1871 | 5580 | 10440180 | |
2018-09-03 0:00 | c업체 | 1871 | 1871 | 5580 | 10440180 | ||
2018-09-03 0:00 | c업체 | 2510 | 11160 | 14005800 | |||
2018-09-03 0:00 | d업체 | 3800 | 0 | 0 | 3800 | 0 | 0 |
2018-09-03 0:00 | d업체 | 3800 | 0 | 3800 | 0 | 0 | |
2018-09-03 0:00 | d업체 | 3800 | 3800 | 0 | 0 | ||
2018-09-03 0:00 | d업체 | 853 | 0 | 0 | 853 | 0 | 0 |
2018-09-03 0:00 | d업체 | 853 | 0 | 853 | 0 | 0 | |
2018-09-03 0:00 | d업체 | 853 | 853 | 0 | 0 | ||
2018-09-03 0:00 | d업체 | 4653 | 0 | 0 |
공백과 0이 있고 없고 차이인 data가 3줄씩 나오는걸 1줄만 나오게 하려면 어떻게 해야될까요?
IN_DATE | CUST_NAME | MAT_NAME | IN_QTY | IN_UPRICE | IN_AMT |
2018-09-01 0:00 | a업체 | 항목101 | 18342 | 6267 | 114949994 |
합계 | 18342 | 6267 | 114949994 | ||
2018-09-03 0:00 | b업체 | 항목102 | 23972 | 7072 | 169529984 |
합계 | 23972 | 7072 | 169529984 | ||
2018-09-03 0:00 | c업체 | 항목103 | 2657 | 5000 | 13285000 |
2018-09-03 0:00 | c업체 | 항목104 | 88 | 5740 | 505120 |
2018-09-03 0:00 | c업체 | 항목105 | 771 | 5720 | 4410120 |
합계 | 3516 | 16460 | 18200240 | ||
2018-09-03 0:00 | e업체 | 항목104 | 10 | 5730 | 57300 |
2018-09-03 0:00 | e업체 | 항목102 | 272 | 5720 | 1555840 |
합계 | 282 | 11450 | 1613140 | ||
2018-09-03 0:00 | f업체 | 항목106 | 4737 | 0 | 0 |
2018-09-03 0:00 | f업체 | 항목106 | 4670 | 0 | 0 |
2018-09-03 0:00 | f업체 | 항목107 | 1871 | 5580 | 10440180 |
합계 | 11278 | 5580 | 10440180 |
원하는 결과는 위와 같습니다. rollup을 어떻게 써야될지 감이 안잡히네요
조언부탁드립니다.