zoukankan      html  css  js  c++  java
  • mysql 实行模糊查询 一个输入值匹配多个字段和多个输入值匹配一个字段

    mysql 实行模糊查询  一个输入值匹配多个字段

    MySQL单表多字段模糊查询可以通过下面这个SQL查询实现 为啥一定要150字以上  真的麻烦  还不让贴代码了

    SELECT * FROM `magazine` WHERE CONCAT(`title`,`tag`,`description`) LIKE ‘%关键字%’

    实例:

        select * from mcode_specific_information where 1=1
                  <if test="typeID!=null and typeID !=''">
                      and typeID like "%"#{typeID}"%" 
                  </if>
                  <if test="typeName!=null  and typeName !=''">
                      and typeName like "%"#{typeName}"%" 
                  </if>
                  <if test="entryUnit!=null  and entryUnit !=''">
                      and entryUnit like "%"#{entryUnit}"%" 
                  </if>
                  <if test="alias!=null  and alias !=''">
                      and CONCAT(`alias`,`alias1`,`alias2`) like "%"#{alias}"%" 
                  </if>
                  <if test="alias1!=null  and alias1 !=''">
                      and CONCAT(`alias`,`alias1`,`alias2`)  like "%"#{alias1}"%" 
                  </if>
                  <if test="alias2!=null  and alias2 !=''">
                      and CONCAT(`alias`,`alias1`,`alias2`)  like "%"#{alias2}"%" 
                  </if>
                  

     当一个字段想模糊查询出多个字段的时候,正常情况下一般会这么作

    1 select * from a where name like 'a%' or name like 'b%' ....or ...;

    但是上面的情况只能对应少量的模糊查询值,过多之后再后台开发的时候会出现非常麻烦的sql语句拼接

    这时我们可以采用正则表达式进行匹配

    1 select * from a where name regexp'a|b|...';
  • 相关阅读:
    ffmpeg 合并文件
    win10 设备摄像头,麦克风,【隐私】权限
    负载均衡,过载保护 简介
    《用Python做科学计算》 书籍在线观看
    Getting Started with OpenMP
    Algorithms & Data structures in C++& GO ( Lock Free Queue)
    PostgreSQL新手入门
    Ubuntu 网络配置
    QT 4.7.6 驱动 罗技C720摄像头
    使用vbs脚本添加域网络共享驱动器
  • 原文地址:https://www.cnblogs.com/liaoxun/p/10318264.html
Copyright © 2011-2022 走看看