具有与Excel VLookup相同功能的SQL Server查询 [英] SQL Server query with same functionality as Excel VLookup
本文介绍了具有与Excel VLookup相同功能的SQL Server查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2列需要相互比较的数据-列A和列B.
I have 2 columns of data that I need to compare with each other - Column A and Column B.
A列:
Steve
Jane
Mary
Peter
Ed
Scott
Ted
B列:
Peter
Scott
David
Nancy
- A列的数据量比B列大.
- 但是它可能没有B列中的所有值.
我需要找出B列中的哪些值也位于A列中.
I need to find out which of the values in column B are also in column A.
上述示例数据的预期输出:
Output expected for above sample data:
Peter TRUE
Scott TRUE
David FALSE
Nancy FALSE
- 需要使用SQL Server/T-SQL来获取此输出.
- A列和B列是2个单独表中的字段
- 2个表中没有其他列
感谢您的所有帮助!
推荐答案
select
b.columnb,
case when a.columna is null then 'FALSE' else 'TRUE' end
from
tableb b left outer join
tablea a on b.columnb = a.columna
这篇关于具有与Excel VLookup相同功能的SQL Server查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文