【发布时间】:2021-12-30 09:42:06
【问题描述】:
我有一个数据透视表输出,现在我想检查数据透视列中的值,如果另一个表的另一列中的值为 null,则替换这些值。
| Invoice_No | Column | value |
|---|---|---|
| 111 | A | One |
| 111 | B | Two |
| 111 | C | Three |
| 111 | E | Five |
(SELECT Invoice_No, new_value, Column_Name FROM table_name)
PIVOT(max(new_value)
FOR Column_Name IN ('A','B','C','D','E'))
这返回了下表
| Invoice_No | 'A' | 'B' | 'C' | 'D' | 'E' |
|---|---|---|---|---|---|
| 111 | One | Two | Three | null | Five |
现在,我想将 D 列中的空值替换为另一个表中与 Invoice_no 匹配的值。
with temp as
(SELECT Invoice_No, new_value, Column_Name FROM table_name)
PIVOT(max(new_value)
FOR Column_Name IN ('A','B','C','D','E'))
select nvl(temp.D,bckup.D)
from
(select A,B,C,D,E from Backup_table) bckup
join
temp
on
temp.Invoice_No = bckup = Invoice_No
现在,我收到 D 列不存在的错误消息。
【问题讨论】:
标签: oracle join null pivot nvl