【问题标题】:Vlookup in SQl tableSQL 表中的 Vlookup
【发布时间】:2021-03-15 11:29:43
【问题描述】:

表1

Agent           id
A              1
B              2
C              3 
D              4
E              5

表2

Agent          id
C               3 
D               4

输出:

Agent           id
A               1
B               2 
E               3

【问题讨论】:

  • SQL 表没有名为“vlookup”的操作。你的问题不清楚。
  • SQL 中VLookup 的等价物可能字面意思是在WHERE 中具有横向连接的子查询,尽管您可能需要正确的JOINFROM.
  • 在源数据中Agent='E'id=5,在输出中它有id=3。为什么?

标签: mysql sql sql-server subquery


【解决方案1】:

你想要not exists吗?

select t1.*
from table1 t1
where not exists (select 1 from table2 t2 where t2.agent = t1.agent and t2.id = t1.id)

这会带来table1 的记录,而table2 中没有相应记录。我假设您希望在两列上都进行匹配:您可以查看该内容,并相应地调整子查询的 where 子句。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    • 1970-01-01
    相关资源
    最近更新 更多