Skip to content
Advertisement

how to select third, fourth, fifth date in sql using window function

The table rental of movies has this data:

how to generate pairs of :

first rental_ts, second rental date,

second rental, third rental date, ….

second LAST rental date, last rental date,

last rental date, null?

using window functions- this is not working:

i expect:

basically i need more than 1 level back – but dont know how to use it, i only used 1 lead() or lag() at work to compare current and previous dates

Advertisement

Answer

Don’t you need to use dynamic pivot? But if you want it this way then you can use lead(rental_ts,2), lead(rental_ts,3) etc…

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement