日期:2014-05-19  浏览次数:20535 次

如何得到1个表中N天没有记录的信息。
id       name       xtdate             number     type
1         冰箱     2007-02-05         2               销售
2         电视     2007-02-05         2               销售
3         冰箱     2007-02-10         3               销售


希望搜索出2007-02-06   日以后没有销售记录的信息。结果:
2         电视     2007-02-10         2               销售

------解决方案--------------------
declare @t table(id int identity(1,1),name varchar(20),xtdate datetime,number int,type varchar(20))
insert into @t select '冰箱 ', '2007-02-05 ', 2, '销售 '
insert into @t select '电视 ', '2007-02-05 ', 2 , '销售 '
insert into @t select '冰箱 ' , '2007-02-10 ' , 3 , '销售 '
select * from @t
select a.id,a.name, '2007-02-06 ' as xtdate,a.number,a.type from @t a where not exists(select 1 from @t where name=a.name and xtdate> '2007-02-06 ')