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

Help required on the query using analytic function - response (4) by dnoeth

$
0
0
Hi Bala, #1: recursion is a parallel operation, so it's much faster than a cursor which is processed serially #2: There's no built-in recursion level limit and there's no option like MAXRECURSION. You have to do it on your own and add a column calculating the level: WITH RECURSIVE cte (rn, a, b, start_time, end_time, lvl) AS ( SELECT rn, a, b, start_time, start_time + INTERVAL '23:59:59' HOUR TO SECOND AS end_time, CAST(1 AS SMALLINT) AS lvl FROM vt WHERE rn=1 UNION ALL SELECT vt.rn, vt.a, vt.b, vt.start_time, CASE WHEN vt.start_time > cte.end_time THEN vt.start_time + INTERVAL '23:59:59' HOUR TO SECOND ELSE cte.end_time END, lvl + 1 FROM vt JOIN cte ON vt.a = cte.a AND vt.b = cte.b AND vt.rn = cte.rn+1 WHERE lvl < 20 ) SELECT * FROM cte ORDER BY start_time;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>