我有一个表,里面有一些重复的业务数据,我希望能把那些重复的数据删除掉并只保留任意一条记录。
CustomerID CustomerName CreateTime
--------------------------------------- ---------------------------- --------------------
EFA9A40D-02B2-4796-8C70-3EF2B35F3B46 城建院园林所 2012-07-30 11:38:17.590
6F9394E2-A7BB-4420-9CEB-96D1B5807B02 城建院园林所 2012-08-10 17:51:49.057
A9B42B03-3285-41C6-8161-3FB041E58673 城开集团城开龙城置业 2012-08-30 10:39:45.887
4BEFB44B-F198-4B1F-814C-1B157E4D9546 滁州市发能房地产有限公司 2013-01-17 10:32:20.460
5BF4D307-C9C7-44EE-B477-02C2009AC37F 创鸿集团 2012-09-27 16:50:05.500
5B137B18-7FA0-4714-8FBB-542BC8F8F03D 创鸿集团 2012-09-27 16:45:22.780
8614BBF3-D4C6-4A36-8BFF-AEF7DBB774A1 创鸿集团 2012-11-23 15:08:12.377
最终的结果我要是这样的:
CustomerID CustomerName CreateTime
--------------------------------------- ---------------------------- ---------------------
EFA9A40D-02B2-4796-8C70-3EF2B35F3B46 城建院园林所 2012-07-30 11:38:17.590
A9B42B03-3285-41C6-8161-3FB041E58673 城开集团城开龙城置业 2012-08-30 10:39:45.887
4BEFB44B-F198-4B1F-814C-1B157E4D9546 滁州市发能房地产有限公司 2013-01-17 10:32:20.460
5BF4D307-C9C7-44EE-B477-02C2009AC37F 创鸿集团 2012-09-27 16:50:05.500
------解决方案--------------------
DELETE A FROM [TB] A WHERE EXISTS(SELECT 1 FROM [TB] WHERE CustomerName=A.CustomerName AND CreateTime>A.CreateTime)
------解决方案--------------------
select CustomerID,CustomerName,CreateTime ,rownum from (
select CustomerID,CustomerName,CreateTime ,
ROW_NUMBER() over(partition by CustomerName order by CreateTime) as rownum from t0326