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
  • 4,467
  • 5
  • 15
  • 19

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,816
  • 5
  • 30
  • 52
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786