我找到了 Jeff Smith 的解决方案,它显示了两个表之间的差异:
SELECT MIN(TableName) as TableName, ID, COL1, COL2, COL3 ...
FROM
(
SELECT 'Table A' as TableName, A.ID, A.COL1, A.COL2, A.COL3, ...
FROM A
UNION ALL
SELECT 'Table B' as TableName, B.ID, B.COL1, B.COl2, B.COL3, ...
FROM B
) tmp
GROUP BY ID, COL1, COL2, COL3 ...
HAVING COUNT(*) = 1
ORDER BY ID
在我的项目中,我需要比较例如。仅 col1 和 col2,rest 用于其他操作。我试着用
HAVING (COUNT(col1) = 1 and COUNT(col2) = 1)
但没有效果。
您能否为我提供解决方案?