背景
根据名称的长度从临时表中删除重复的城市名称。
问题
以下查询返回 350,000 行:
select
tc.id,
tc.name_lowercase,
tc.population,
tc.latitude_decimal,
tc.longitude_decimal
from
climate.temp_city tc
inner join (
select
tc2.latitude_decimal,
tc2.longitude_decimal
from
climate.temp_city tc2
group by
tc2.latitude_decimal,
tc2.longitude_decimal
having
count(*) > 3
) s on
tc.latitude_decimal = s.latitude_decimal and
tc.longitude_decimal = s.longitude_decimal
样本数据:
940308;"sara" ;;-53.4333333;-68.1833333
935665;"estancia la sara";;-53.4333333;-68.1833333
935697;"estancia sara" ;;-53.4333333;-68.1833333
937204;"la sara" ;;-53.4333333;-68.1833333
940350;"seccion gap" ;;-52.1666667;-68.5666667
941448;"zanja pique" ;;-52.1666667;-68.5666667
935941;"gap" ;;-52.1666667;-68.5666667
935648;"estancia gap" ;;-52.1666667;-68.5666667
939635;"ritchie" ;;-51.9833333;-70.4
934948;"d.e. ritchie" ;;-51.9833333;-70.4
934992;"diego richtie" ;;-51.9833333;-70.4
934993;"diego ritchie" ;;-51.9833333;-70.4
934990;"diego e. ritchie";;-51.9833333;-70.4
我想删除所有重复项,保留以下行:
- 人口不为空;和
- 该名称是重复项中最长的 (
max(tc.name_lowercase));和 - 如果这两个条件都不满足,则保留
max(tc.id).
从给定的数据集中,剩余的行将是:
935665;"estancia la sara";;-53.4333333;-68.1833333
935648;"estancia gap" ;;-52.1666667;-68.5666667
934990;"diego e. ritchie";;-51.9833333;-70.4
问题
您将如何仅选择具有重复经纬度值且符合问题标准的行?
谢谢!