SQL - 如何从where子句列表中返回不在表中的ID?

Abb*_*boq 2 sql db2

给出这样的查询:

select customerId
  from customer
 where customerId in (
          1, 2, 3
       )
Run Code Online (Sandbox Code Playgroud)

我在where条款列表中有数百个ID ; 如何从where子句中不在表中的列表中返回ID ?

这是一个我只能运行select查询的生产表.我只能运行select查询; 我没有权限创建任何表.

Leo*_*ons 6

您可以使用VALUES语句伪造SELECT中的表:

SELECT t1.customerId
FROM
  (VALUES (1), (2), (3), (4)) AS t1(customerId)
LEFT OUTER JOIN
  customer c
ON
  c.customerId = t1.customerId
AND
  c.customerId IS NULL
Run Code Online (Sandbox Code Playgroud)

参考