在SQL中删除重复项和几乎重复项(缺少值)

问题描述 投票:0回答:1

我需要一种删除重复行的方法,该方法还可以删除等同但有一些缺失值的行。即我有

ID   FIRST LAST  YEAR CITY    COUNTRY
1    John  SMITH 1985 NewYork USA
1    John  NULL  1985 NULL    USA
1    NULL  SMITH NULL Miami USA
1    John  SMITH 1985 NewYork USA

我需要:

1    John  SMITH 1985 NewYork USA
1    NULL  SMITH NULL Miami   USA

类似于这个问题:

SQL Remove almost duplicate rows

但是,在我的数据中,任何变量(ID除外)都可以为NULL。如果我在SAS中执行此操作有帮助,那么proc SQL或SAS数据步骤就可以了。

sql sas duplicates missing-data
1个回答
0
投票

您要聚合吗?

select id, first, last, min(year) year, min(city) city, min(country) country
from mytable
group by id, first, last
© www.soinside.com 2019 - 2024. All rights reserved.