如何在SAP HANA Studio中验证/识别两个SQL查询,以确保数据是否与两个查询输出中的数据都匹配?

时间:2018-09-27 13:45:47

标签: sql sap hana

我有一个问题,有人可以帮助我吗?

我有两个SQL查询,一个是在报表计算视图顶部的查询,另一个是在报表CV的基本CV上的查询。现在,我需要比较两个输出是否匹配。

有人可以为此建议SQL查询吗?

这是我要在SAP HANA Studio中获取输出的查询:

Select *   
From 
    (Select X, Y  
     From Table1 
     Minus 
     Select X,Y 
     From Table2);

还有其他建议吗?

非常感谢

问候 钱德拉巴布

2 个答案:

答案 0 :(得分:0)

这是我的选择:

第一

 SELECT * FROM  
    (
        SELECT "X", "Y" FROM Table1
        EXCEPT
        SELECT "X", "Y" FROM Table2
    )
    UNION
    (
        SELECT "X", "Y" FROM Table2
        EXCEPT
        SELECT "X", "Y" FROM Table1
    );

第二:

SELECT "X", "Y" FROM
(
    SELECT "X", "Y" FROM Table1
     UNION ALL
    SELECT "X", "Y" FROM Table2
)
GROUP BY
    "X", "Y"
HAVING COUNT(1) = 1;

第三:

SELECT 
    IFNULL(T1."X",T2."X") AS "X",
    IFNULL(T1."Y",T2."Y") AS "Y"
FROM
    Table1 T1
    FULL OUTER JOIN Table2 T2 ON T1."X" = T2."X" AND T1."Y" = T2."Y" 
WHERE
    T1."X" IS NULL OR T2."X" IS NULL;

答案 1 :(得分:0)

使用FULL OUTER JOIN,可以显示公共项目以及两个表与其他表之间的差异

这是查询

select table1.*, table2.* 
from table1
full outer join table2
    on table1.x = table2.x and
       table1.y = table2.y;

结果在这里

enter image description here