首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么得到1个表中N天没有记录的信息

2012-01-10 
如何得到1个表中N天没有记录的信息。idnamextdatenumbertype1冰箱2007-02-052销售2电视2007-02-052销售3冰

如何得到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 ')

热点排行