我在 Oracle 中有两个大表,它们有两个作业的输出。我有一列在两个表中都有相同的数据。我需要一个查询来根据这个公共字段比较这两个表,并列出其他列上两个表的差异。
我尝试了inner join
的以下示例,但收到此错误:
缺少右括号
SELECT
table1.column1,
table2.column2,
(CASE WHEN (table1.column1 = table2.column2 THEN 'No change' ELSE 'Change DETECTED' END)) AS Difference
FROM
table1 INNER JOIN table2 ON table1.id=table2.id
答案 0 :(得分:2)
从CASE
部分删除括号:
SELECT table1.column1,
table2.column2,
CASE
WHEN table1.column1 = table2.column2 THEN 'No change'
ELSE 'Change DETECTED'
END
AS Difference
FROM table1 INNER JOIN table2 ON table1.id = table2.id
答案 1 :(得分:1)
像这样修改您的查询:
SELECT table1.column1
, table2.column2
, CASE WHEN table1.column1 = table2.column2
THEN 'No change'
ELSE 'Change DETECTED' END AS Difference
FROM table1 INNER JOIN table2 ON table1.id = table2.id