Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Teradata sql grouping - response (4) by gerardo

$
0
0

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 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>