前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mysql 字段包含某个字符的函数

mysql 字段包含某个字符的函数

作者头像
凯哥Java
发布2019-06-28 17:27:40
5.8K0
发布2019-06-28 17:27:40
举报
文章被收录于专栏:凯哥Java

 通过sql查询语句,查询某个字段中包含特定字符串:

例子:查询e_book表的types字段包含字符串"3",有下面4种方式

代码语言:javascript
复制
select * from e_book where types like "%3%";

select * from e_book where find_in_set('3', types);

select * from e_book where locate('3', types);


select * from e_book where INSTR(types,'3');

第2、3中方式相对速度较快

如果使用find_in_set不行的话,可以换成locate.

使用案例:

98a49bc8402555846c0170606776462a.png
98a49bc8402555846c0170606776462a.png
代码语言:javascript
复制
select * from (
        select
                cb.id, cb.code, cb.contract_type contractType, cb.target,b.real_name targetName,
                cb.start_date startDate, cb.end_date endDate, cb.real_end_date realEndDate, cb.finance_group_id financeGroupId,
                cb.dept_name jobGroupName,
                cb.job_group_id jobGroupId,
                cb.dept_name_en deptNameEn ,
                cb.create_date createDate, cb.creater, cb.status,
                        cb.dept_code,
                        cb.dept_name_en,
                        cb.dept_name,
                        cb.product_line_code,
                        cb.product_line_name,
                        cb.subject_code,
                cb.subject_name,
                    temp.name as tname,
                     case  when locate('劳务',  temp.name) then '1'
            when locate('服务',  temp.name) then '2'
                end as newType
                from cb_contract cb
                left join base b on cb.target = b.id
                        left join contract_template temp on cb.contract_template = temp.id

                where cb.is_delete = 1    
         
            and dept_code in
             (  
                'DEP0009'
             ) 
         
         ) cb

        where 1=1
        and (
         (newType = '2'
         
            and product_line_code in
             (  
                'PL0092'
             ) 
         
         
        )
        or (newType = '2'  and ( product_line_code is null or product_line_code = ''))
        or (newType = '1' )
        )

        order by cb.id desc
        limit 0, 10
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-01-22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

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

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档