我有两个表:TableA和TableB。
我需要比较两个表中的两个特定列(AnsId& Content)并获得它们的区别。 如果没有发现差异,那么我应该返回'流程成功',否则返回'失败'
TableA
+--------+-----------+---------+-------------+
| Id | RSCId | AnsId | Content |
+--------+-----------+---------+-------------+
| 1 | 12 | 1 | Test data. |
| 2 | 12 | 0 | Sample Test.|
| 3 | 12 | 5 | Test data. |
| 4 | 12 | 7 | Test Data. |
| 5 | 12 | 46 | Test datas. |
+--------+-----------+---------+-------------+
表B
+--------+-----------+---------+-------------+
| Id | RSCId | AnsId | Content |
+--------+-----------+---------+-------------+
| 1 | 35 | 2 | Test . |
| 2 | 35 | 0 | Sample Test.|
| 3 | 35 | 5 | Test data. |
| 4 | 35 | 7 | Test Data. |
| 5 | 35 | 46 | Test datas. |
+--------+-----------+---------+-------------+
请帮帮我。
答案 0 :(得分:0)
select case when sum(case when a.ansid is null or b.ansid is null
then 1
end) > 0
then 'mismatch'
else 'ok'
end as result
from tableA a
full outer join tableB b on a.ansid = b.ansid and a.content = b.content