日期:2014-05-18 浏览次数:20566 次
select a.*
from t1 a left join liushui b
on a.name = b.name and a.danwei = b.danwei
and b.riqi between '2010-01-01' and '2012-02-15'
where b.id is null
------解决方案--------------------
declare @t table(name varchar(10),danwei varchar(20))
insert into @t
select '感康', '盒' union all
select '维C', '盒'
declare @t2 table(id int , name varchar(10), danwei varchar(20), riqi datetime)
insert into @t2
select 1, '感康','盒','2010-01-01' union all
select 2,'感康', '盒', '2012-02-15' union all
select 3, '维C','盒','2012-02-18'
select distinct b.* from @t2 a,@t b
where a.riqi between '2010-01-01' and '2012-02-15'
and a.name != b.name