generate days from date range

后端 未结 29 2492
渐次进展
渐次进展 2020-11-21 05:19

I would like to run a query like

select ... as days where `date` is between \'2010-01-20\' and \'2010-01-24\'

And return data like:

29条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-21 06:10

    Alright.. Try this: http://www.devshed.com/c/a/MySQL/Delving-Deeper-into-MySQL-50/
    http://dev.mysql.com/doc/refman/5.0/en/loop-statement.html
    http://www.roseindia.net/sql/mysql-example/mysql-loop.shtml

    Use that to, say, generate a temp table, and then do a select * on the temp table. Or output the results one at a time.
    What you say you want to do can't be done with a SELECT statement, but it might be doable with things specific to MySQL.
    Then again, maybe you need cursors: http://dev.mysql.com/doc/refman/5.0/en/cursors.html

提交回复
热议问题