MYSQL查询数据表中某个字段包含某个数值 | 您所在的位置:网站首页 › mysql搜索表 › MYSQL查询数据表中某个字段包含某个数值 |
当某个字段中字符串是"1,2,3,4,5,6"或者"123456" 查询数据表中某个字段是否包含某个值 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是否包含'http://'子串,如果不包含则拼接在url字符串开头update site set url =concat('http://',url) where locate('http://',url)=0 注意mysql中字符串的拼接不能使用加号+,用concat函数 方法四:使用instr()函数 SELECT lus.log_id logId,lus.type,lus.score,CASE WHEN INSTR(DATE_FORMAT(lus.create_date,'%Y-%m-%d %p %h:%i'),'AM')>0 THEN REPLACE(DATE_FORMAT(lus.create_date,'%Y-%m-%d %p %h:%i'),'AM','上午')WHEN INSTR(DATE_FORMAT(lus.create_date,'%Y-%m-%d %p %h:%i'),'PM') >0THEN REPLACE(DATE_FORMAT(lus.create_date,'%Y-%m-%d %p %h:%i'),'PM','下午') END AS create_date,lus.create_date AS scoreDate FROM log_user_score lus 参考:https://blog.csdn.net/nookl/article/details/80795956https://www.cnblogs.com/xbxxf/p/13298886.html https://blog.csdn.net/zihandan/article/details/53186042?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param |
CopyRight 2018-2019 实验室设备网 版权所有 |