以下是样本数据
DECLARE @maxval int, @minval int
select @maxval=201301,@minval=201312
SELECT top 100001 CAST(((@maxval + 1) - @minval) *
RAND(CHECKSUM(NEWID())) + @minval AS int)Date ,ceiling (RAND(CHECKSUM(NEWID())) *1000+25692*RAND(CHECKSUM(NEWID())) )*ceiling (RAND(CHECKSUM(NEWID())) *1000+25692*RAND(CHECKSUM(NEWID())) )ID
into #sample from sysobjects , syscolumns
问题:
这是我的代码,它需要更多的人工干预和时间。请协助。
select distinct date from #sample order by DATE
declare @processingdate varchar(6),@from varchar(6),@to varchar(6)
set @processingdate = '201302'
set @from = '201303'
set @to = '201305'
select distinct id into #Source from #sample where DATE = @processingdate
select distinct id into #lookup from #sample where DATE between @from and @to
select @processingdate,count(*) from #Source where ID not in (select * from #lookup)
谢谢
答案 0 :(得分:0)
试试这个:
select *
from #sample a
inner join #sample b
on a.ID = b.ID and a.Date IN (b.Date - 1, b.Date - 2, b.Date - 3)