请问下面的sql怎么拼接成一句sql

set @i = -1;

set @sql = repeat(" select 1 union all",-datediff('2021-01-01','2030-12-31')+1);

set @sql = left(@sql,length(@sql)-length(" union all"));

set @sql = concat("select date_add('2021-01-01',interval @i:=@i+1 day) as date from (",@sql,") as tmp");

prepare stmt from @sql;

execute stmt
比如说我想拼接成这个样子,怎么拼接啊
select * from (select date_add('2012-09-01',interval @i:=@i+1 day) as date
from ( select 1 union all select 1 union all select 1 union all select 1 union all select 1) as tmp,
(select @i:= -1) t) a

2个回答

concat("select date_add('2021-01-01',interval -1:=-1+1 day) as date from (",left(@sql,length(repeat(" select 1 union all",-datediff('2021-01-01','2030-12-31')+1))-length(" union all")),") as tmp");

select date_add('2021-01-01',interval -1:=-1+1 day) as date from (",left(@sql,length(repeat(" select 1 union all",-datediff('2021-01-01','2030-12-31')+1))-length(" union all")),") as tmp

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐