sql in 语句,如何求 结果集 与 in 列表的差集

sql 语句, 如 select id from table where id in ( id 列表),如何求出 id结果集 与 in 括号里面的 id列表 的差集

阅读 1.7k
1 个回答

假设test表的数据如下:

value
1
2
3
4
5

而list为(1,5,11,55),则可以如此实现

with temp as (
  select 1 as value union
 (select 5 as value) union
 (select 11 as value) union
 (select 55 as value) 
) 
select 
    value 
from 
    temp 
where 
    value not in (select value from test where value in (select value from temp)) 

以上代码在mysql8中通过

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题