SELECT 来自值列表

SELECT from a list of values

所以做起来很简单:

Select Val from MyTable where Val not in ('100','200','300'....)
  1. 如何编写查询以便我 select 从列表中获取值。例如,我如何做类似 Select * from ('100','200','300'....) 这样的输出是:

    100    
    200    
    300    
    ...
    
  2. 此外,我该如何做类似 select * from ('100','200','300'....) that are not in MyTable.Val 列的事情?

How do I do something like select * from ('100','200','300'....) that are not in MyTable.Val

您可以使用 values() 构建包含值列表的派生 table,然后 not exists 过滤那些在 table:

select v.*
from (values (100), (200), (300)) v(val)
where not exists (select 1 from mytable t where t.val = v.val)

第 1 部分

Select * from (values ('100'),('200'),('300')) v(val);

第 2 部分

Select * 
from
  (values ('100'),('200'),('300')) v(val)
where not exists (select 1 from myTable t where t.val=v.val);