select a.xldm as lddm,a.xlmc as ldmc,c.xlmc as dfxl, c.fxymc as dfy,d.xlmc as fxxl,e.fxymc as fxr,f.xlmc as shxl,f.xm as shr into #lfy from xldm as a left join xldm as b on a.sjdm=b.xldm and left(b.xlmc,2)='DF'left join fxyxlb as c on b.xlmc=c.xlmc inner join xldm as d1 on right(a.xldm,5)=right(d1.xldm,5) and left(d1.xldm,1)='0' inner join xldm as d on d1.sjdm=d.xldm and left(d.xlmc,1)='F' inner join fxyxlb as e on d.xldm=e.xldm and left(e.xlmc,1)='F' inner join xldm as f1 on right(a.xldm,5)=right(f1.xldm,5) and left(f1.xldm,1)='0' left join shsz as f on f1.sjdm=f.xldm and left(f.xlmc,1)='S' where left(a.xldm,1)='8' and c.xlmc<>'' and f.xlmc<>'' order by a.lddm 仅供参考!!
union all
select * from 表2 where 条件2
union all
select * from 表2 where 条件2
右连接:ritht (full) join
外连接:outer (full) join
c.fxymc as dfy,d.xlmc as fxxl,e.fxymc as fxr,f.xlmc as shxl,f.xm as shr into #lfy
from xldm as a left join xldm as b on a.sjdm=b.xldm and left(b.xlmc,2)='DF'left join fxyxlb as c on b.xlmc=c.xlmc
inner join xldm as d1 on right(a.xldm,5)=right(d1.xldm,5) and left(d1.xldm,1)='0'
inner join xldm as d on d1.sjdm=d.xldm and left(d.xlmc,1)='F'
inner join fxyxlb as e on d.xldm=e.xldm and left(e.xlmc,1)='F'
inner join xldm as f1 on right(a.xldm,5)=right(f1.xldm,5) and left(f1.xldm,1)='0'
left join shsz as f on f1.sjdm=f.xldm and left(f.xlmc,1)='S'
where left(a.xldm,1)='8' and c.xlmc<>'' and f.xlmc<>''
order by a.lddm
仅供参考!!