时间天数相差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 行受影响)
*/
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 行受影响)
*/
相关文章推荐
- 查询当天、本周、本月记录 获取大于跟当前时间相差几天的语句 .(Z)
- 查询当天、本周、本月记录 获取大于跟当前时间相差几天的语句
- 开启sharepoint2007文档稽核功能,记录文档开启(下载),修改等用户及时间和其他信息
- 如何记录 Linux 的系统运行时间的统计信息
- sqlite找出时间相差3天的记录
- java 中计算两个时间相差天数
- python计算两个时间之间相差的天数
- 使用my97对区间日期进行操作的时候,后一个时间必须大于前一个时间,并且不可以超过当前的时间
- 字符串转成NSDate类型,计算与当前时间的相差,年数,天数,时分秒……
- [记录]时间处理相关:返回某月的天数
- 如何记录应用的接口访问信息(调用次数,最长时间、最短时间、平均时间等等)
- 撤销表空间的切换+修改撤销记录保留的时间+查看参数的值+查询表空间信息
- C/C++中计算两个时间相差的天数
- mssql 计算 时间 日期 相差 天数 时间
- java Web项目中,利用其过滤功能,实现访问者每次访问服务器时,记录访问者的IP,访问时间,Url等信息,并保存到文件的操作
- 启用mysql日志记录执行过的sql并且开启慢查询记录所有超过慢查询时间的SQL以及未使用索引SQL
- My97DatePicker:开始时间和结束时间的最大间隔为1个月30天,并且不大于当前时间(3种方法)
- iOS-字符串转化成NSDate类型 计算与当前时间的相差 月数 天数
- C#获取时间相差天数
- MYSQL计算两日期/时间之间相差的天数,秒数...分钟