前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >给一个list查询哪些在表中哪些不在

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

原创
作者头像
葫芦
修改2022-04-13 00:39:20
6800
修改2022-04-13 00:39:20
举报
文章被收录于专栏:葫芦葫芦

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

代码语言:javascript
复制
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


葫芦的运维日志-王梓个人博客

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 给一个list查询哪些在表中哪些不在
  • select values from a list return that are in table and that are not in table
    • 测试表
      • test table
        • 查询的列表
          • select list
            • 查询语句
              • select sql
              • 葫芦的运维日志-王梓个人博客
              相关产品与服务
              数据库
              云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档