若何經由過程SQL找出2個內外值分歧的列的辦法。本站提示廣大學習愛好者:(若何經由過程SQL找出2個內外值分歧的列的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是若何經由過程SQL找出2個內外值分歧的列的辦法正文
以下有兩個表,他們的構造完整雷同,請經由過程SQL找出值分歧的列。
Student_1
NAME AGE SCORE peter 26 100 jack 25 96 daniel 26 48 bark 21 69
Student_2
NAME AGE SCORE peter 26 89 jack 25 96 daniel 26 48 bark 21 69
辦法一 -- NOT EXISTS:
SELECT *
FROM Student_1 S1
WHERE NOT EXISTS
(SELECT *
FROM Student_2 S2
WHERE S1.name = S2.name
AND S1.age = S2.age
AND S1.score = S2.score
)
UNION ALL
SELECT *
FROM STUDENT_2 S2
WHERE NOT EXISTS
(SELECT *
FROM STUDENT_1 S1
WHERE S1.name = S2.name
AND S1.age = S2.age
AND S1.score = S2.score
);
辦法二 -- MINUS
(SELECT * FROM Student_1
MINUS
SELECT * FROM Student_2)
UNION ALL
(SELECT * FROM Student_2
MINUS
SELECT * FROM Student_1)
辦法三 -- HAVING GROUP BY
SELECT DISTINCT name, age, score FROM (
SELECT * FROM Student_1
UNION ALL
SELECT * FROM Student_2
)GROUP BY name, age, score HAVING COUNT(*)=1 ;