如何在SQL SERVER中编写查询重复记录的存储过程,请教!

来源:百度知道 编辑:UC知道 时间:2024/05/30 19:14:56
我在一张表名为RealTimeData的表中有realtime, machineid, flux, pressure 等7个字段名,其中realtime, machineid 字段中会出现完全重复的几条记录,我想在数据库中编写一个存储过程用于查询这几条记录,并显示出这些重复记录的所有字段内容,急用!
我用的是SQL SERVER 2000,无主键,因为数据量过大需要批量处理,无法简单的采用SELECT语句;

你的数据库表的主键是什么啊?设为primarykey吧
以下查询语句就行了
select * from RealTimeData r where exists(select * from RealTimeData where realtime=r.realtime and machineid=r.machineid and primarykey!=r.primarykey)

不知道你数据库类型,存储过程你自己写好了

无主键的话就有点难查了,因为查询的时候会查到自己的,你后面在加上剩下的所有字段
create proc sel_duplicate
as
select * from RealTimeData r where exists(select * from RealTimeData where realtime=r.realtime and machineid=r.machineid and flux!=r. flux and pressure!=r.pressure 等等)
go

exec sel_duplicate