To obtain ththe output as you have indicated, the sql:
SEL VENDOR,
COALESCE(LOCATION,'TOTAL ') AS LOCATION ,
SEPT,
OCT,
TOTAL2013
FROM (
SEL VENDOR,
LOCATION,
SUM(CASE WHEN EXTRACT (MONTH FROM DATE_KEY) =9 THEN CALL_CNT ELSE 0 END) AS SEPT ,
SUM(CASE WHEN EXTRACT(MONTH FROM DATE_KEY) =10 THEN CALL_CNT ELSE 0 END) AS OCT,
SEPT + OCT AS TOTAL2013
FROM DW_USUARIO.TEST
GROUP BY GROUPING SETS((1),(1,2))
) AS AA
ORDER BY VENDOR , COALESCE(LOCATION,'ZZZZ'):
The result is_:
Vendor LOCATION SEPT OCT TOTAL2013
att Highlands 1500 200 1700
att Utah 800 0 800
att TOTAL 2300 200 2500
Verizon Cupertino 200 0 200
Verizon San jose 400 0 400
Verizon TOTAL 600 0 600
To obtain ththe output as you have indicated, the sql:
SEL VENDOR,
COALESCE(LOCATION,'TOTAL ') AS LOCATION ,
SEPT,
OCT,
TOTAL2013
FROM (
SEL VENDOR,
LOCATION,
SUM(CASE WHEN EXTRACT (MONTH FROM DATE_KEY) =9 THEN CALL_CNT ELSE 0 END) AS SEPT ,
SUM(CASE WHEN EXTRACT(MONTH FROM DATE_KEY) =10 THEN CALL_CNT ELSE 0 END) AS OCT,
SEPT + OCT AS TOTAL2013
FROM DW_USUARIO.TEST
GROUP BY GROUPING SETS((1),(1,2))
) AS AA
ORDER BY VENDOR , COALESCE(LOCATION,'ZZZZ'):
The result is_:
Vendor LOCATION SEPT OCT TOTAL2013
att Highlands 1500 200 1700
att Utah 800 0 800
att TOTAL 2300 200 2500
Verizon Cupertino 200 0 200
Verizon San jose 400 0 400
Verizon TOTAL 600 0 600