Calcifer Calcifer 2
Sql

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

2022/04/13 00:06 4025 次阅读 王梓
打赏
✸ ✸ ✸

给一个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
✸ ✸ ✸

📜 版权声明

本文作者:王梓 | 原文链接:https://www.bthlt.com/note/14255805-Sql给一个list查询哪些在表中哪些不在

出处:葫芦的运维日志 | 转载请注明出处并保留原文链接

📜 留言板

留言提交后需管理员审核通过才会显示