浏览量 2282
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 |