日期:2014-05-18 浏览次数:20554 次
这是表的结构 CREATE TABLE [dbo].[Table_1]( [ID] [int] IDENTITY(1,1) NOT NULL, [GDSCode] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL, [ExHotelCode] [int] NULL, [ExRoomCode] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL, [ExRatePlaneCode] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL, [HotelID] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL, [RoomID] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL, [RatePlaneID] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL, CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] 这是删除重复数据的SQL语句: DELETE FROM Table_1 WHERE --c.ID=2 (GDSCode, a.ExHotelCode, a.ExRoomCode,a.ExRatePlaneCode,a.HotelID, a.RoomID,a.RatePlaneID) IN (SELECT c.GDSCode, c.ExHotelCode, c.ExRoomCode,c.ExRatePlaneCode, c.HotelID, c.RoomID,c.RatePlaneID FROM Table_1 c GROUP BY c.GDSCode,c.ExHotelCode, c.ExRoomCode,c.ExRatePlaneCode, c.HotelID, c.RoomID,c.RatePlaneID HAVING COUNT(*)>1) AND a.ID NOT IN(SELECT MIN(ID) FROM Table_1 b GROUP BY b.GDSCode, b.ExHotelCode, b.ExRoomCode,b.ExRatePlaneCode, b.HotelID, b.RoomID,b.RatePlaneID HAVING COUNT(*)>1)
delete a from TB a where exists(select 1 from TB where Name=a.Name and ID<a.ID)--只保留一条记录
------解决方案--------------------
delete a from Table_1 a
where exists(select 1 from Table_1 where Name=a.Name and ID>a.ID)
------解决方案--------------------
处理表重复记录(查询和删除)_整理贴4
ORACLE中不熟悉...