select a.Date
from (
select curdate() - INTERVAL (a.a + (10 * b.a) + (100 * c.a) + (1000 * d.a) ) DAY as Date
from (select 0 as a 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) as a
cross join (select 0 as a 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) as b
cross join (select 0 as a 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) as c
cross join (select 0 as a 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) as d
) a
where a.Date between ‘2020-05-01‘ and ‘2020-05-05‘
效果:
BEGIN
#循环结束标志 1 时结束循环
DECLARE v_finished INTEGER DEFAULT 0;
#游标里的数据循环赋值给 v_summary
DECLARE v_summary varchar(100) DEFAULT "";
#声明游标 DECLARE cursor_name CURSOR FOR SELECT_statement;
DECLARE s_cursor CURSOR FOR SELECT summary FROM posts;
#异常处理
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finished = 1;
#打开游标
OPEN s_cursor;
#开始循环
get_summary:LOOP
#依次处理游标
FETCH s_cursor INTO v_summary;
#循环结束条件
IF v_finished = 1 THEN
LEAVE get_summary;
END IF;
-- build list
SET summary_list = CONCAT(v_summary,";",summary_list );
#结束循环
END LOOP get_summary;
#关闭游标
CLOSE s_cursor;
END
表结构:
原文:https://www.cnblogs.com/qifengle1412/p/12893904.html