SQL 查找重复记录
2013-07-27 10:29
369 查看
SQL 查找重复记录
USE TEST GO IF EXISTS(SELECT * FROM SYSOBJECTS WHERE NAME = 'product') DROP TABLE product CREATE TABLE product ( ID INT IDENTITY(1,1) PRIMARY KEY NOT NULL, Pid INT NOT NULL, Pname VARCHAR(50) NOT NULL, Punit CHAR(10) NOT NULL, Pspec VARCHAR(50), PbarCode VARCHAR(20), ) INSERT INTO product(Pid,Pname,Punit,Pspec,PbarCode) VALUES(10000,'欧莱雅日间修复','瓶','50ML','1975126589653') INSERT INTO product(Pid,Pname,Punit,Pspec,PbarCode) VALUES(10001,'欧莱雅夜间修复','瓶','50ML','1975126589643') INSERT INTO product(Pid,Pname,Punit,Pspec,PbarCode) VALUES(10002,'倩碧','盒','150ML','1545126589653') INSERT INTO product(Pid,Pname,Punit,Pspec,PbarCode) VALUES(10003,'百分百','瓶','250ML','2575126589653') INSERT INTO product(Pid,Pname,Punit,Pspec,PbarCode) VALUES(10004,'欧本洗面脸','瓶','80ML','1275126589653') INSERT INTO product(Pid,Pname,Punit,Pspec,PbarCode) VALUES(10005,'艾迪达斯','瓶','40ML','1975126589653') INSERT INTO product(Pid,Pname,Punit,Pspec,PbarCode) VALUES(10006,'SK2','瓶','20ML','1975126589653') --查某一列(或多列)的重复值(只能查出重复记录的值,不能整个记录的信息) --如:查找barCode 重复的记录 select PbarCode from product group by PbarCode having(count(*))>1 --查找重复条形码商品 select * from product where PbarCode in ( select PbarCode from product group by PbarCode having(count(*))>1 ) --查找重复条形码商品二,跟上面的结果是一样的 by 李全 select * from product where PbarCode in (select PbarCode from (select p1.PbarCode,count(p1.PbarCode) number from product p1,(select distinct(PbarCode) from product) p2 where p1.PbarCode=p2.PbarCode group by p1.PbarCode) a1 where number>1) --将表重命名 sp_rename 'product1','product' 原网址:http://blog.csdn.net/eastlift/article/details/1456984 |
相关文章推荐
- SQL重复记录处理(查找,过滤,删除)
- sql查找重复记录
- SQL 查找重复记录
- 关于sql数据表中查找重复记录的技巧
- 查找sql表中多余的重复记录
- SQL 查找重复记录
- SQL重复记录处理(查找,过滤,删除)
- SQL 查找重复记录
- SQL语句查找重复记录
- SQL 查找重复记录
- SQL删除、查找重复数据记录等操作
- Oracle SQL中查找和删除重复记录方法
- sql查找不重复记录
- SQL重复记录处理(查找,过滤,删除)
- SQL 查找重复记录
- (小笔记)(sql)查找重复记录,并删除多余记录
- SQL重复记录处理(查找,过滤,删除)
- T-SQL 查找重复记录
- DB2查找重复记录SQL
- SQL重复记录处理(查找,过滤,删除)