MySql多列模糊查詢(使用concat)

2021-09-30 01:38:02 字數 849 閱讀 6457

1.concat簡介

concat(str1,str2,…)

返回結果為連線引數產生的字串。如有任何乙個引數為null ,則返回值為 null。或許有乙個或多個引數。 如果所有引數均為非二進位制字串,則結果為非二進位制字串。 如果自變數中含有任一二進位制字串,則結果為乙個二進位制字串。乙個數字引數被轉化為與之相等的二進位制字串格式;若要避免這種情況,可使用顯式型別 cast, 例如: select concat(cast(int_col as char), char_col)

mysql> select concat(『my』, 『s』, 『ql』);

-> 'mysql'
mysql> select concat(『my』, null, 『ql』);

-> null
mysql> select concat(14.3);

-> '14.3'
concat_ws(separator,str1,str2,…)

2.使用

之前使用mysql對多字段模糊查詢

select * from 表名where 列名1 like '%***%' or 列名2 like '%***%' or 列名3 like '%***%'
列多時,手動拼接很多列,or很多列。

使用concat()

select * from 表名 where concat(列名1,列名2,列名3) like '%***%';
搞定,列相當於變數,等於把變數的值先用concat』拼接在一起,構成一新的值,再對這個值進行模糊查詢

mysql模糊查詢 MYSQL模糊查詢

mysql提供標準的sql模式匹配,以及一種基於象unix實用程式如vi grep和sed的擴充套件正規表示式模式匹配的格式。一 sql模式 sql的模式匹配允許你使用 匹配任何單個字元,而 匹配任意數目字元 包括零個字元 在 mysql中,sql的模式預設是忽略大小寫的。下面顯示一些例子。注意在你...

Mysql多列分組查詢 示列詳解

一張表 按照時間,按照時間,id分組 源表 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 select flowdata.store id,flowdata.create hour as createhour,sum in count hourincoun...

mysql模糊查詢索引 MySQL模糊查詢全文索引

全文索引 mysql front dump 2.5 host localhost database test server version 4.0.12 nt log table structure for table t3 create table t3 name char 12 not null...