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

找出表中 10秒之内 不同数据的个数,小弟我没方法了。求高手

2012-03-17 
找出表中 10秒之内 不同数据的个数,我没方法了。求高手表结构基本这样的。--------------------------------

找出表中 10秒之内 不同数据的个数,我没方法了。求高手
表结构基本这样的。
-----------------------------------
产生时刻 | 号码 |
-----------------------------------
2007-2-7 14:31:17 1234
2007-2-7 14:31:20 1234
2007-2-7 14:33:12 1544
2007-2-7 14:41:10 1111
————————————————————
问题是这样的。
我要计算这个表里,共有多少行数据 但要除去 产生时刻 在20秒之内 号码 相同的数据行。
比如上面 的 计算结果就应该是 3 因为第二行数据是在20秒之内的同一个号码。
用SQL怎么写??? 在此谢过。
 

[解决办法]

SQL code
select count(1) from tab awhere not exists (   select 1 from tab    where 号码=a.号码 and 产生时刻 between a.产生时刻 and dateadd(ss,20,a.产生时刻)   )
[解决办法]
SQL code
create table #t(dt datetime,col int)insert into #t values('2007-2-7   14:31:17',1234)insert into #t values('2007-2-7   14:31:20',1234)insert into #t values('2007-2-7   14:33:12',1544)insert into #t values('2007-2-7   14:41:10',1111)select count(1) from #t a where not exists (select 1 from #t where dt>a.dt and dt<=dateadd(ss,20,a.dt)  and col=a.col)-----------3(1 行受影响) 

热点排行