从日期范围生成天数我想运行这样的查询select ... as days where `date` is between '2010-01-20' and '2010-01-24'并返回如下数据:days
----------
2010-01-20
2010-01-21
2010-01-22
2010-01-23
2010-01-24
4 回答
精慕HU
TA贡献1845条经验 获得超8个赞
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;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;CREATE VIEW dates AS SELECT SUBDATE(CURRENT_DATE(), number) AS date FROM numbers;
SELECT dateFROM datesWHERE date BETWEEN '2010-01-20' AND '2010-01-24'ORDER BY date
更新
CREATE VIEW dates AS SELECT SUBDATE(CURRENT_DATE(), number) AS date FROM numbers UNION ALL SELECT ADDDATE(CURRENT_DATE(), number + 1) AS date FROM numbers;
添加回答
举报
0/150
提交
取消