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|...';