本文介绍了我需要比较两个表并仅显示匹配的列和状态。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的桌子价值低于
table1
Hi,
I have a table with below values
table1
id
10802000320601
10802000320602
10802000320603
10802000320604
10802000320605
10802000320606
10802000320607
10802000320608
10802000320609
10802000320610
10802000320611
10802000320612
10802000320613
table2
table2
id
10802000320601
10802000320602
10802000320603
10802000320604
10802000320605
10802000320606
我需要比较两个表并仅显示匹配的列和状态。
示例:输出
I need to compare two tables and display only matched columns and status.
Example: Output
id Status
10802000320601 Matched
10802000320602 Matched
10802000320603 Matched
10802000320604 Matched
10802000320605 Matched
10802000320606 Matched
10802000320607 Unmatched
10802000320608 Unmatched
10802000320609 Unmatched
10802000320610 Unmatched
10802000320611 Unmatched
10802000320612 Unmatched
10802000320613 Unmatched
帮助我。
Help me.
推荐答案
SELECT t1.id, CASE WHEN t2.id IS NULL THEN 'Unmatched' ELSE 'Matchaed' END AS 'CompareResult'
FROM Table1 AS t1 LEFT JOIN Table2 AS t2 ON t1.id = t2.ID
想法:获取Table1中的所有数据,并且只获得table2中相同的这些数据。如果table2中的id为NULL,则表示''Unmatched''。
Idea: get all data from Table1 and only these data which are equal in table2. If id in table2 is NULL, then it means ''Unmatched''.
这篇关于我需要比较两个表并仅显示匹配的列和状态。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!