如何找到缺漏了哪些数据?

yangala 2006-12-23 04:13:25
我有一个程序采集硬件设备上的数据,然后会每一秒钟往data表里添加一条数据,时间放在rectime(datetime类型)中.要求要data表里面连续地每一秒都有一条数据,如何找到缺漏了哪些数据呢?
求解决的办法
...全文
159 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangala 2006-12-23
  • 打赏
  • 举报
回复
原来@tb是表变量:)

不知道效率还能不能继续提高
yangala 2006-12-23
  • 打赏
  • 举报
回复

感谢marco08(天道酬勤)

再问一下,
@tb是不是虚拟的表?
我打算把上面的代码写成存储过程,多次调用之后那个@tb会不会自动释放内存呀?

然后,效率能不能再提高呢?
我这个data表有100多万条记录的,并且每天的数据都会增加很多条
marco08 2006-12-23
  • 打赏
  • 举报
回复
create table T(rectime datetime)
insert T select '2006-12-22 16:44:18.000'
union all select '2006-12-22 16:44:17.000'
union all select '2006-12-22 16:44:14.000'
union all select '2006-12-22 16:44:13.000'
union all select '2006-12-22 16:44:11.000'
union all select '2006-12-22 16:44:10.000'


declare @tb table(rectime datetime)

declare @beg_DT datetime, @end_DT datetime
select @end_DT=max(rectime) from T
select @beg_DT=min(rectime) from T
while @beg_DT<=@end_DT
begin
if not exists(select * from T where rectime=@beg_DT)
insert @tb select @beg_DT

set @beg_DT=dateadd(ss, 1, @beg_DT)
end

select * from @tb

--result
rectime
------------------------------------------------------
2006-12-22 16:44:12.000
2006-12-22 16:44:15.000
2006-12-22 16:44:16.000

(3 row(s) affected)
yangala 2006-12-23
  • 打赏
  • 举报
回复
这样不行吧...
比如我的表里面有如下数据:
rectime
------------------------------------------------------
2006-12-22 16:44:18.000
2006-12-22 16:44:17.000
2006-12-22 16:44:14.000
2006-12-22 16:44:13.000
2006-12-22 16:44:11.000
2006-12-22 16:44:10.000

要求查询的结果如下:(查询的时间范围在查询是指定)
2006-12-22 16:44:16.000
2006-12-22 16:44:15.000
2006-12-22 16:44:12.000
caixia615 2006-12-23
  • 打赏
  • 举报
回复
select * from tablename where 数据 not in(select 数据 from date)

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧