我有一个从CRM软件生成的表,它在不同的行中有很多重新编辑的个人,但每次重复都有不同的字段,类似于这样:
id | birth_date | sex | ostal_code||||
---|---|---|---|---|---|---|
001 | NULL | 00067是 | ||||
001 | NULL | 雄性 | 001 | 1994年3月21日 | >NULL00067 | |
002 | ||||||
002 | NULL | 9986否 | ||||
003 | 1986年1月13日 | NULL |
您可以聚合行并获取最大非空值,如:
select
id,
max(birth_date) as birth_date,
max(sex) as sex,
max(postal_code) as postal_code,
max(customer) as customer,
max(smoker) as smoker
from t
group by id
现在,当同一个人有两个不同的出生日期时,这个解决方案不会考虑不一致的数据。