sql 给一个list查询哪些在表中哪些不在

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 1692

2022/04/13 00:06


给一个list查询哪些在表中哪些不在

select values from a list return that are in table and that are not in table

数据库 mysql

测试表

test table

name
wz
hl

查询的列表

select list

[ 'xm' ,'xw' ,'xl' ,'wz' ,'bt' ,'hh']


查询语句

select sql

select temp.name,if(temp.name = test.name,1,0) as 'is_null' from   (
select 'xm' as name
union all select 'xw'
union all select 'xl'
union all select 'wz'
union all select 'bt'
union all select 'hh'
) as temp
left join test on temp.name=test.name

return

name is_null
xm 0
xw 0
xl 0
wz 1
bt 0
hh 0

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号-1