MSsql删除重复记录,字段A重复了,但是字段B中:一条记录有数据,另一
1个回答
展开全部
oracle中在一张表中某个字段下面有重复记录,有很多方法,但是有一个方法,是比较"高效"的,如下语句:
SELECT data_guid
FROM adam_entity_datas a
WHERE a.rowid > (SELECT MIN(b.rowid)
FROM adam_entity_datas b
WHERE b.data_guid = a.data_guid)
如果表中有大量数据,但是"重复数据比较少",那么可以用下面的语句提高效率
SELECT data_guid
FROM adam_entity_datas
WHERE data_guid IN (SELECT data_guid
FROM adam_entity_datas
GROUP BY data_guid
HAVING COUNT(*) > 1)
此方法查询出所有重复记录了,也就是说,只要是重复的就选出来,下面的语句也许"更高效"
SELECT data_guid
FROM adam_entity_datas
WHERE ROWID IN (SELECT rid
FROM (SELECT ROWID rid,
row_number() over(PARTITION BY data_guid ORDER BY ROWID) m
FROM adam_entity_datas)
WHERE m <> 1)
SELECT data_guid
FROM adam_entity_datas a
WHERE a.rowid > (SELECT MIN(b.rowid)
FROM adam_entity_datas b
WHERE b.data_guid = a.data_guid)
如果表中有大量数据,但是"重复数据比较少",那么可以用下面的语句提高效率
SELECT data_guid
FROM adam_entity_datas
WHERE data_guid IN (SELECT data_guid
FROM adam_entity_datas
GROUP BY data_guid
HAVING COUNT(*) > 1)
此方法查询出所有重复记录了,也就是说,只要是重复的就选出来,下面的语句也许"更高效"
SELECT data_guid
FROM adam_entity_datas
WHERE ROWID IN (SELECT rid
FROM (SELECT ROWID rid,
row_number() over(PARTITION BY data_guid ORDER BY ROWID) m
FROM adam_entity_datas)
WHERE m <> 1)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询