--这样?declare @a table
(
id int,
datecreate datetime,
days int
)
insert into @a
select 1,'2006/6/1',4 union all
select 1,'2006/6/5',3 union all
select 1,'2006/6/15',4 union all
select 1,'2006/6/20',4select idx=identity(int,1,1),* into # from @a
go
select * from #
go
select *
from # a
where datediff(dd,dateadd(dd,days,datecreate),(select datecreate from # where idx=a.idx+1))>=4
or
(
(idx=(select max(idx) from #))
and datediff(dd,dateadd(dd,days,datecreate),'2006/7/1')>=4)
go
drop table #
go/*
idx         id          datecreate                                             days        
----------- ----------- ------------------------------------------------------ ----------- 
1           1           2006-06-01 00:00:00.000                                4
2           1           2006-06-05 00:00:00.000                                3
3           1           2006-06-15 00:00:00.000                                4
4           1           2006-06-20 00:00:00.000                                4
idx         id          datecreate                                             days        
----------- ----------- ------------------------------------------------------ ----------- 
2           1           2006-06-05 00:00:00.000                                3
4           1           2006-06-20 00:00:00.000                                4*/