SELECT
case when GROUPING_ID(stockInDay,materialCode)='1' then '소계'
when GROUPING_ID(stockInDay,materialCode)='3' then '총계'
else stockInDay end as stockInDay,
materialCode,
case when dimension is null and materialCode is not null then '소계' else materialName end materialName ,
dimension,
domesticText,
sum(realQty) realQty,
unitName,
sellerCode,
sellerName,
storeCode,
storeName,
isSellingvat,
sellingPrice,
sum(sellingTotal) sellingTotal,
sum(sellingAmt) sellingAmt,
sum(sellingVat) sellingVat,
remark,
restrictCount,
modifierDate,
sellermaterialcode,
remark2,
handphone,
address
FROM (
select
a.stockInDay,
a.materialCode,
b.materialName,
b.dimension,
b.domesticText,
a.materialQty-a.rtnQty as realQty,
DBO.UF_UNITNAME(b.unitCode) as unitName,
a.sellerCode,
DBO.UF_SELLERNAME(a.dealerCode,a.sellercode) as sellerName,
a.storeCode,
case when a.storecode = '9999' then '창고입고'
else ( case when len(replace(a.storetype,' ',''))>0 then DBO.UF_STORENAME(a.dealerCode,a.storeCode)+'('+replace(a.storetype,' ','')+')' else DBO.UF_STORENAME(a.dealerCode,a.storeCode) end ) end as storeName,
a.isSellingvat,
a.sellingPrice,
a.sellingAmt+a.sellingVat as sellingTotal,
a.sellingAmt,
a.sellingVat,
a.remark,
(case when a.orders_restrictcount is null then 'D-'+isnull(b.restrictCount,'1') else 'D-'+a.orders_restrictcount end) as restrictCount,
a.modifierDate ,
b.sellermaterialcode,
isnull(a.domesticText,'') as remark2,
(select handphone from client where dealerCode='1713' and clientCode=a.storeCode) as handphone,
(select address from client where dealerCode='1713' and clientCode=a.storeCode) as address
from orders a,material b
where a.dealerCode='1713'
and a.dealerCode=b.dealerCode
and a.materialCode=b.materialCode
and a.stockinDay between '20220622' and '20220622'
and ((a.storeCode !='9999' and a.isWareHouse='D') or storeCode ='9999')
) t
group by rollup((stockInDay),(sellerCode,sellerName,materialName,materialCode),(
dimension,
domesticText,
unitName,
storeCode,
storeName,
isSellingvat,
sellingPrice,
remark,
restrictCount,
modifierDate,
sellermaterialcode,
remark2,
handphone,
address))
ORDER BY GROUPING(t.stockinday ), t.stockinday
, GROUPING(t.sellercode ), t.sellercode
, GROUPING(t.materialName), t.materialName
, GROUPING(t.materialCode), t.materialCode
쿼리문이구요.. 사진처럼 고기산적이 6개로 나와야하는데
어떤이유인진 몰라도 몇몇개가 합쳐져서 4개로 나옵니다.. 무슨현상인가요 ㅠㅠ
+원인은 찾았씁니다.. 결과값이 완전 똑같으면 합쳐지는 모양인데 이거 막을수있는 방법이 있을까요
1. 유니크한 항목을 그룹바이에 추가하세요.
예) PK, ROWNUM 등
2. 그리고...
앞서 조언했던 부분은 전혀 반영이 안되고 있네요. ㅠ,.ㅠ
합계 항목은 그룹바이에서 제거하세요.
예) realQty, sellingTotal, sellingAmt, sellingVat
그룹바이 롤업에 추가하라는 말입니다.
아 합계항목 제거하는걸 잊어버렸습니다 죄송합니다.. 유니크한 항목이라고 하셨는데
pk를 select문 위에 넣으라는 말씀이신가요??
그리고. 괄호안에 함께 묶여 있는 항목들에 대한 그룹핑 값은 모두 동일합니다.
(stockinday, sellercode, materialName, materialCode)
즉, 각각의 GROUPING(항목) 을 하는 것은 무의미해 보입니다.
GROUPING(t.stockinday) 하나만 있으면 되고 나머지 필요 없고
4가지 항목 외에 기타 항목들 중에서도 정렬 기준이 추가되어야 합니다.
GROUPING_ID(stockInDay,materialCode) 부분도 마찬가지네요.
함께 묶여 있는 녀석들로 GROUPING_ID 를 할 이유가 없습니다.
기존 ROLLUP (stockInDay,materialCode) 에서는 GROUPING_ID(stockInDay,materialCode) 가 의미가 있지만
지금 ROLLUP ((stockInDay,materialCode)) 에서는 GROUPING_ID(stockInDay,materialCode) 는 의미가 없습니다.
GROUPING(t.stockinday) 하나만 있으면 되고 나머지 필요 없고
4가지 항목 외에 기타 항목들 중에서도 정렬 기준이 추가되어야 합니다.
=====> 현재 정렬기준이 1. stockinday 2. sellercode 3.materialName 4.materialcode 순인데
stockinday만 있다면 뒤에 2,3,4번은 적용이 안되는거 아닌가요??
GROUPING_ID(stockInDay,materialCode) 부분도 마찬가지네요.
함께 묶여 있는 녀석들로 GROUPING_ID 를 할 이유가 없습니다.
기존 ROLLUP (stockInDay,materialCode) 에서는 GROUPING_ID(stockInDay,materialCode) 가 의미가 있지만
지금 ROLLUP ((stockInDay,materialCode)) 에서는 GROUPING_ID(stockInDay,materialCode) 는 의미가 없습니다.
=============> 아 저렇게하면 속도저하가 일어날수있는 상황인가요??
rollup에 유니크한 항목 넣으라는 말씀 감사합니다! 해결했습니다
1. stockinday만 있다면 뒤에 2,3,4번은 적용이 안되는거 아닌가요??
- 정령항목 중 GROUPING(항목) 부분을 제거하라는 것입니다.
- 항목 자체를 제거하라는게 아닙니다.
2. 아 저렇게하면 속도저하가 일어날수있는 상황인가요??
- 성능을 논하는게 아닙니다.
- 의미를 말하는 것입니다.