Попробуйте это:
WITH T (DEALER, REP, GROUP, DTL1, Dtl2, QUANT, LAST_SHIP_DATE) AS (
VALUES (21177, 165, 4867, 2878, 29, 1, CURRENT DATE - 10 DAY),
(19445, 182, 4867, 2878, 29, 1, CURRENT DATE - 10 DAY),
(20949, 340, 4867, 2878, 29, 2, CURRENT DATE - 10 DAY),
(21347, 353, 4867, 2878, 29, 1, CURRENT DATE - 10 DAY),
(23068, 353, 4867, 2878, 29, 1, CURRENT DATE - 10 DAY),
(17195, 353, 4867, 2878, 29, 6, CURRENT DATE - 10 DAY),
(23040, 353, 4867, 2878, 29, 1, CURRENT DATE - 10 DAY),
(5620, 380, 4867, 2878, 29, 4, CURRENT DATE - 10 DAY),
(23009, 380, 4867, 2878, 29, 3, CURRENT DATE - 10 DAY),
(13529, 390, 4867, 2878, 29, 1, CURRENT DATE - 10 DAY),
(22706, 394, 4867, 2878, 29, 1, CURRENT DATE - 10 DAY),
(17049, 394, 4867, 2878, 29, 4, CURRENT DATE - 10 DAY),
(17879, 397, 4867, 2878, 29, 1, CURRENT DATE - 10 DAY),
(21320, 445, 4867, 2878, 29, 1, CURRENT DATE - 10 DAY),
(21231, 457, 4867, 2878, 29, 1, CURRENT DATE - 10 DAY)
, (1, 1, 4867, 2878, 29, 1, CURRENT DATE - 100 DAY)
)
SELECT T.DEALER, T.REP, T.GROUP, T.DTL1, T.Dtl2, T.QUANT
/*
, SUM(CASE WHEN last_ship_date > CURRENT_DATE - 30 DAYS THEN QUANT END) OVER(PARTITION BY DEALER, GROUP, DTL1, Dtl2) V1
, SUM(CASE WHEN last_ship_date > CURRENT_DATE - 30 DAYS THEN QUANT END) OVER(PARTITION BY REP, GROUP, DTL1, Dtl2) V2
, SUM(CASE WHEN last_ship_date > CURRENT_DATE - 30 DAYS THEN QUANT END) OVER(PARTITION BY GROUP, DTL1, Dtl2) V3
FROM T;
*/
, COALESCE(T1.V1, 0) V1, COALESCE(T2.V2, 0) V2, COALESCE(T3.V3, 0) V3
FROM T
LEFT JOIN (
SELECT DEALER, GROUP, DTL1, Dtl2, SUM(QUANT) V1
FROM T
WHERE last_ship_date > CURRENT_DATE - 30 DAYS
GROUP BY DEALER, GROUP, DTL1, Dtl2
) T1 ON T1.DEALER=T.DEALER AND T1.GROUP=T.GROUP AND T1.DTL1=T.DTL1 AND T1.DTL2=T.DTL2
LEFT JOIN (
SELECT REP, GROUP, DTL1, Dtl2, SUM(QUANT) V2
FROM T
WHERE last_ship_date > CURRENT_DATE - 30 DAYS
GROUP BY REP, GROUP, DTL1, Dtl2
) T2 ON T2.REP=T.REP AND T2.GROUP=T.GROUP AND T2.DTL1=T.DTL1 AND T2.DTL2=T.DTL2
LEFT JOIN (
SELECT GROUP, DTL1, Dtl2, SUM(QUANT) V3
FROM T
WHERE last_ship_date > CURRENT_DATE - 30 DAYS
GROUP BY GROUP, DTL1, Dtl2
) T3 ON T3.GROUP=T.GROUP AND T3.DTL1=T.DTL1 AND T3.DTL2=T.DTL2;