我有一个包含世界上所有城市的数据库。
如果我运行this查询,我可以看到有双打:
我已经使用此查询删除所有重复的行:
WITH CTE AS
(
SELECT *,ROW_NUMBER()
OVER (PARTITION BY Country, City, AccentCity, Region, Population, latitude, Longitude
ORDER BY Country, City, AccentCity, Region, Population, latitude, Longitude) AS RN
FROM ExperimentWorld
)
DELETE FROM CTE WHERE RN<>1
我现在再次运行它并删除latitude
和Longitude
相同的所有列,如果两行相同,如上图所示,我想保留{{1}有一些价值并删除population
&#39; 0&#39;
答案 0 :(得分:2)
尝试此查询 -
;WITH CTE
AS (
SELECT *
,ROW_NUMBER() OVER (
PARTITION BY Country
,City
,AccentCity
,Region
,Population
,latitude
,Longitude ORDER BY Population DESC
) AS RowNum
FROM ExperimentWorld
)
DELETE
FROM CTE
WHERE RowNum > 1