为了说明这一点,我们创建以下视图 -
mysql> create view digits as -> select 0 as digit union all -> select 1 union all -> select 2 union all -> select 3 union all -> select 4 union all -> select 5 union all -> select 6 union all -> select 7 union all -> select 8 union all -> select 9;query ok, 0 rows affected (0.08 sec)mysql> create view numbers as select ones.digit + tens.digit * 10 + hundreds.digit * 100 + thousands.digit * 1000 as number from digits as ones, digits as tens, digits as hundreds, digits as thousands;query ok, 0 rows affected (0.09 sec)mysql> create view dates1 as select subdate(current_date(), number) as date from numbers union all select adddate(current_date(), number + 1) as date from numbers;query ok, 0 rows affected (0.09 sec)mysql> select date from dates1 where date between '2017-11-15' and '2017-11-30'order by date;+------------+| date |+------------+| 2017-11-15 || 2017-11-16 || 2017-11-17 || 2017-11-18 || 2017-11-19 || 2017-11-20 || 2017-11-21 || 2017-11-22 || 2017-11-23 || 2017-11-24 || 2017-11-25 || 2017-11-26 || 2017-11-27 || 2017-11-28 || 2017-11-29 || 2017-11-30 |+------------+16 rows in set (0.05 sec)
以上就是如何借助 mysql 视图从日期范围生成天数?的详细内容。