比较两列,其中一列为null

时间:2016-05-19 13:54:48

标签: oracle

我有三张表格如下

TABLE1
ID           VALUE
1             NULL
TABLE2
ID           VALUE
1                1
TABLE3
ID           VALUE
1               10

我正在尝试执行以下操作:

比较表1和表1中的两个字段(ID) 2如果一个为null,则返回null,然后从TABLE3返回值。

2 个答案:

答案 0 :(得分:0)

看来你正在寻找这样的东西:

select table3.id, table3.value
from table1 join table2 on table1.id = table2.id
            join table3 on table1.id = table3.id
where table1.value is null or table2.value is null

如果这不是您的想法,您需要提供有关您的要求的更多详细信息。

答案 1 :(得分:0)

尝试此查询:

SELECT t1.id,
       (CASE WHEN t1.value IS NULL OR t2.value IS NULL 
             THEN t3.value
       END) VALUE
  FROM table_1 t1
  JOIN table_2 t2
    ON t1.id = t2.id
  JOIN table_3 t3
    ON t1.id = t3.id