How to generate all dates between two dates

后端 未结 2 1044
無奈伤痛
無奈伤痛 2020-12-03 15:48

How can I retrieve all dates between \'2015-10-02\' to \'2015-11-02\' in SQLite? (String type) Result will be like:

\'2015-10-03\'
\'2015-10-04\'
\'2015-10-0         


        
2条回答
  •  醉梦人生
    2020-12-03 16:17

    This is not possible without a recursive common table expression, which was introduced in SQLite 3.8.3:

    WITH RECURSIVE dates(date) AS (
      VALUES('2015-10-03')
      UNION ALL
      SELECT date(date, '+1 day')
      FROM dates
      WHERE date < '2015-11-01'
    )
    SELECT date FROM dates;
    

提交回复
热议问题