Hi Dieter,
Thanks for the query.Your query works amazing as per the requirement.
I have few questions on that:
1) Recrsion an multiple AMP operation as per the PI we create or an Single AMP Operation like cursor?
2) Also to avoid the infinite looping in the recursive view,can we add an condition to the query or use an recursive hint ?
ex: OPTION (MAXRECURSION 20)
Query with condition:
----------------------------
WITH RECURSIVE cte (rn, a, b, start_time, end_time)
AS
(
SELECT rn, a, b, start_time,start_time + INTERVAL '23:59:59' HOUR TO SECOND AS end_time
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 FROM
vt
JOIN
cte
ON vt.a = cte.a
AND vt.b = cte.b
AND vt.rn = cte.rn+1
AND cte.end_time < max(vt.start_time + INTERVAL '24' HOUR)
)
SELECT * FROM cte ORDER BY start_time ;
Thanks,
Bala
↧