0

Can anyone fluent in both MySQL and PostgreSQL translate this to MySQL?

SELECT *
FROM  generate_series(DATE_TRUNC('day', NOW() - interval '30 day'),
                            DATE_TRUNC('day', NOW()),
                            interval '1 day'
                           )

I know that generate_series() does not exist in MySQL. Is there a similar function?

bgame2498
  • 3,557
  • 4
  • 14
  • 17

1 Answers1

0

There is no equivalent. MySQL doesn't have CTEs, generate_series(), or even window functions.

If you have a table that is big enough (in this case 31 rows), you can do:

select (curdate() - interval (@rn := @rn + 1) day) as dte
from t cross join
     (select @rn := -1)
limit 31;
SandPiper
  • 2,645
  • 4
  • 26
  • 43
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709