0

I would like to create a temporary table in MySQL which would return 365 rows, each for all 365 days which preceded today.

In SQL Server I would do this:

with
dates as (SELECT dateadd(day,-365,cast(getdate() as date)) as daten union all select dateadd(day,+1,daten) from dates where daten<dateadd(day,-1,getdate()))

select * from dates

option(maxrecursion 0)

Is there a way to obtain something similar in MySQL?

Thank you.

foebu
  • 1,365
  • 2
  • 18
  • 35
  • check this http://stackoverflow.com/questions/10132024/how-to-populate-a-table-with-a-range-of-dates – Pரதீப் Jan 30 '15 at 17:28
  • I might also recommend persisting this calendar table so that you don't have to waste the CPU every time to construct the table a new in memory (minimal though it is, in this particular case). – Xedni Jan 30 '15 at 18:53

0 Answers0