日期:2014-05-18 浏览次数:20580 次
declare @A table (dm varchar(3),jc varchar(2)) insert into @A select '001','上' union all select '002','下' union all select '003','上' union all select '004','下' declare @B table (dm varchar(3),km int) insert into @B select '001',1 union all select '001',2 union all select '002',1 union all select '002',2 union all select '002',3 union all select '003',3 select d.dm,d.col from (select * from @A a cross join (select 1 as col union select 2 union select 3)c where a.dm in (select dm from @B))d full join @B b on d.col=b.km and d.dm=b.dm where b.km is null order by 1 /* dm col ---- ----------- 001 3 003 1 003 2 */