日期:2014-05-17 浏览次数:20627 次
with t1(cityid,cityname)
as(
select 1,'北京' union all
select 2,'海淀' union all
select 3,'丰台' union all
select 4,'上海' union all
select 5,'宝山'
),
T2(cityid,Lever)
as(
select 1,1 union all
select 2,11 union all
select 3,12),
cte as(
select t1.cityid,t1.cityname,t2.lever from t1 join t2 on t1.cityid=t2.cityid where t1.cityname='北京' union all
select t.cityid,t.cityname,t.lever from(select t1.cityid,t1.cityname,t2.lever from t1 join t2 on t1.cityid=t2.cityid)t join cte c on t.cityid!=c.cityid and left(t.lever,len(rtrim(c.lever)))=rtrim(c.lever)
)select * from cte