日期:2014-05-18 浏览次数:20562 次
-- 建立初始数据 CREATE TABLE Person ( PersonId INT IDENTITY(1,1) PRIMARY KEY, PersonName NVARCHAR(50), IdCard NVARCHAR(50), PersonGender NCHAR(2), Birthday DATETIME DEFAULT GETDATE() ) INSERT INTO Person (PersonName,IdCard,PersonGender,Birthday) VALUES('a','123456789012345678',1,'1970-1-2') INSERT INTO Person (PersonName,IdCard,PersonGender,Birthday) VALUES('a','123456789012345677',1,'1970-1-3') INSERT INTO Person (PersonName,IdCard,PersonGender,Birthday) VALUES('a','123456789012345678',1,'1970-1-2') INSERT INTO Person (PersonName,IdCard,PersonGender,Birthday) VALUES('b','123456789012345678',1,'1970-1-2') INSERT INTO Person (PersonName,IdCard,PersonGender,Birthday) VALUES('b','123456789012345677',2,'1970-1-3') INSERT INTO Person (PersonName,IdCard,PersonGender,Birthday) VALUES('c','123456789012345676',1,'1970-1-3')
create index xx_oo on person(personname,idcard,PersonId)
------解决方案--------------------
不知这种方法是否可以解决你的问题
select distinct p1.Personid,p1.PersonName,p1.idCard from Person as P1 , Person as p2 where p1.PersonName=p2.PersonName and p1.IdCard<>p2.idCard
------解决方案--------------------
给予多方面考虑,建议lz建索引,比较好,因为你的数据量在不断增加,这个将来肯定是查询的瓶经所在,不如把问题在前面处理,这样以后就好办了。