mysql中获取两个日期之间的连续日期列表的sql
应用:做报表的时候,查询的日期数据缺少某些日期的,补全日期信息的时候可用,用左外或右外连接补全
- 1.创建一个中间日期表
CREATE TABLE num (i int);
INSERT INTO num (i) VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9);
2.查询sql
select adddate('2012-09-01', numlist.id) as 'date' from
(SELECT n1.i + n10.i*10 + n100.i*100 AS id FROM num n1 cross join
num as n10 cross join num as n100) as numlist
where adddate('2012-09-01', numlist.id) <= '2012-09-10';