您的位置:首页 > 其它

时间天数相差5天以上并且记录条数大于2的信息

2010-01-03 11:31 253 查看
ifnotobject_id('Tempdb..#T') isnull
droptable #T
Go
Createtable #T([ID]int,[NAME]nvarchar(1),[DTIME]Datetime)
Insert #T
select1,N'张','2007-12-15'unionall
select2,N'刘','2008-10-12'unionall
select3,N'王','2009-10-13'unionall
select4,N'赵','2009-12-15'unionall
select5,N'孙','2009-12-17'unionall
select6,N'于','2009-12-14'unionall
select7,N'李','2009-12-10'unionall
select8,N'高','2009-12-01'unionall
select9,N'金','2009-12-10'
Go
Select*from #T

select*from[表名]wheredatediff(day,DTIme,getdate())>5and[Name]in (select[Name]from[表名]groupby[Name]havingcount([Name])>2)

declare@iint
select@i=count(*) from #T whereDateDiff(day,[DTIME],getdate()) >5
if@i>2
select*from #T whereDateDiff(day,[DTIME],getdate()) >5

/*
ID NAME DTIME
----------- ---- -----------------------
1 张 2007-12-15 00:00:00.000
2 刘 2008-10-12 00:00:00.000
3 王 2009-10-13 00:00:00.000
7 李 2009-12-10 00:00:00.000
8 高 2009-12-01 00:00:00.000
9 金 2009-12-10 00:00:00.000

(6 行受影响)
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐