Home > Net >  Query giving consecutive dates for following weeks
Query giving consecutive dates for following weeks

Time:10-12

Is it possible to create a table in SQL, in which 1 column gives the consecutive Sundays. The other column has the upcoming 7 sundays corresponding to each sunday on column1. Expected output below:

enter image description here

Any help is extremely appreciated.

CodePudding user response:

Try the following:

select date_Sundays,
       date_add(date_Sundays,
                interval 7*row_number() over (partition by date_sundays order by date_sundays) day)
       as nextSundays 
from tbl

See a enter image description here

  • Related