• 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|...';
  • 相关阅读:
    SP是什么?CP是什么?SP与CP有什么区别?
    SP与CP将走向互补融合
    SP与CP分工
    Asynchronous Socket 顺序
    Asynchronous Client Socket Example
    Synchronous Server Socket Example
    web应用程序根目录
    简单socket服务(一)
    Asynchronous Server Socket Example
    Socket连接不上的问题
  • 原文地址:https://www.cnblogs.com/liaoxun/p/10318264.html
Copyright © 2020-2023  润新知