选择具有复杂条件的不同行



我有一个从CRM软件生成的表,它在不同的行中有很多重新编辑的个人,但每次重复都有不同的字段,类似于这样:

ostal_code>NULL9986
id birth_date sex
001 NULL 00067是
001 NULL 雄性 001 1994年3月21日00067
002
002 NULL
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

现在,当同一个人有两个不同的出生日期时,这个解决方案不会考虑不一致的数据。

最新更新