将两行分组,但最后两列值不同

Group the two rows but Last 2 columns value is different

我有下面的 table,其中我从不同的 table 中获取数据。

Policy_Number Name_Of_Client Email Phone
BEI/BGAMMQ/0000431 Test, Lda t@t.com NULL
BEI/BGAMMQ/0000431 Test, Lda NULL 1212121212

有人可以帮我得到如下结果吗?

Policy_Number Name_Of_Client Email Phone
BEI/BGAMMQ/0000431 Test, Lda t@t.com 1212121212

提前致谢

按保单编号和客户名称聚合,然后 select 电子邮件的最大值和 phone。

SELECT Policy_Number, Name_Of_Client, MAX(Email) AS Email, MAX(Phone) AS Phone
FROM yourTable
GROUP BY Policy_Number, Name_Of_Client;

顺便说一下,您的 table 当前状态可能意味着存在某种设计或数据收集问题。您想要的输出是您可能应该使用的版本。