Quantcast
Channel: Teradata Forums - All forums
Viewing all articles
Browse latest Browse all 27759

How to sum up the columns total value in the last row - response (2) by dnoeth

$
0
0

 
If this query is run in SQL Assistant you can simply press F4 in the answer set window to get a final row with sums for all numeric columns.
If this is a BTEQ script you could add a WITH SUM(TOTAL_DOLLAR_AMT), SUM(TOTAL_ACCTS) at the end of the query. I'm not shure if the syntax is correct, didn't use that for years.
Otherwise use GROUPING SETS which can return multiple aggregation levels within the same query:

Select LOB , CMPGN_NAME ,INC_TRXN_CD as TRANSACTION_CD  , sum ( INC_AMT ) as TOTAL_DOLLAR_AMT  , count (*) as TOTAL_ACCTS from UD466.FF_PRCSS where Elg_Flg='Y'
group by grouping sets ((1,2,3), ())

To sort your result you should use GROUPING like

order by grouping(LOB), LOB, grouping(CMPGN_NAME), CMPGN_NAME, grouping(INC_TRXN_CD), INC_TRXN_CD

 
Dieter


Viewing all articles
Browse latest Browse all 27759

Trending Articles



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