MYSQL查询数据表中某个字段包含某个数值
当某个字段中字符串是"1,2,3,4,5,6"或者"123456"
查询数据表中某个字段是否包含某个值
mysql中select
1:模糊查询使⽤like
select * from 表 where 字段 like '%1%';
2:函数查  find_in_set(str,数组)
select * from 表 where find_in_set('1','字段');
注意:mysql字符串函数 find_in_set(str1,str2)函数是返回str2中str1所在的位置索引,str2必须以","分割开。其中strlist只识别英⽂逗号。
3.使⽤locate(substr,str)函数,如果包含,返回>0的数,否则返回0
例⼦:判断site表中的url是否包含''⼦串,如果不包含则拼接在url字符串开头
update site set url =concat('',url) where locate('',url)=0
注意mysql中字符串的拼接不能使⽤加号+,⽤concat函数
⽅法四:使⽤instr()函数
SELECT lus.log_id pe,lus.score,
CASE WHEN INSTR(DATE_ate_date,'%Y-%m-%d %p %h:%i'),'AM')>0
THEN  REPLACE(DATE_ate_date,'%Y-%m-%d %p %h:%i'),'AM','上午')
WHEN INSTR(DATE_ate_date,'%Y-%m-%d %p %h:%i'),'PM') >0
THEN REPLACE(DATE_ate_date,'%Y-%m-%d %p %h:%i'),'PM','下午') END AS create_date,
scoreDate FROM log_user_score lus