当一种类型有两组具有空值和有效值时,为字段获取有效值

Fetch valid value for a field when one type has two groups with null value and valid value

我有一个 table 如下:

ID  Amt type            accnum  rcnum   amt
1   Recovery type 1                 [NULL]  45
1   Total recovery                  [NULL]  34
1   Current Type 1      2345        123     23
1   Total current type              [NULL]  12
1   Current type 1                  [NULL]  78
1   Current rvrsl                   [NULL]  -908

现在我想创建如下所示,其中总结了每种类型的金额,但如果存在则将填充有效值,否则 NULL/blank 将被填充:

ID  Amt type            accnum  rcnum   amt
1   Recovery type 1                 [NULL]  45
1   Total recovery                  [NULL]  34
1   Current Type 1      2345        123     101
1   Total current type              [NULL]  12
1   Current rvrsl                   [NULL]  -908

我正在尝试进行左连接,但我不确定如何在不删除其他记录的情况下实现这一点。

这看起来像聚合:

select id, amt_type, accnum, max(rcnum), sum(amt)
from t
group by id, amt_type, accnum;

聚合函数忽略 NULL 个值。