答案 0 :(得分:0)
由于MySQL
没有递归功能,您必须创建一个表格,例如Years
,并根据您的数据填写年份范围(例如2010年至2017年)
创建Years
表后,LEFT JOIN
将其创建到您的表
declare @tbl as table (
car varchar(15)
,model varchar(15)
,startY int
,endY int
)
declare @years as table(year int)
insert into @tbl values ('audi', 'a1', 2012, 2016)
insert into @years values (2010); insert into @years values (2011)
insert into @years values (2012); insert into @years values (2013)
insert into @years values (2014); insert into @years values (2015)
insert into @years values (2016); insert into @years values (2017)
SELECT
A.car
,A.model
,B.year as Model2
FROM @tbl A
LEFT JOIN @years B
ON B.year BETWEEN A.startY AND A.endY