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

Help needed on recursive sql - response (1) by dnoeth

$
0
0

I can't match your sample data and required output based on your narrative.
But it seems you don't need recursion, a simple OLAP function might be enough:

SELECT
   SUM(tot_cost + tot_retail + tot_units) 
   OVER (ORDER BY weekdayofyr
         ROWS BETWEEN 1 PRECEDING AND  1 PRECEDING),
   SUM(cost) AS tot_cost,
   SUM(retail) AS tot_retail, 
   SUM(units) AS tot_units,
   weekdayofyr
FROM tab
GROUP BY weekdayofyr
ORDER BY weekdayofyr

Dieter


Viewing all articles
Browse latest Browse all 14773

Trending Articles



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