mysql 第3.8章 查询-in、find_in_set、like mysql 第3.8章 查询-in、find_in_set、like

2小时前

①、in 查询相当于多个 or 条件的叠加

select * from user where user_id in (1,2,3);
等效于
select * from user where user_id = 1 or user_id = 2 or user_id = 3;
not in与in相反,如下
select * from user where user_id not in (1,2,3);
等效于
select * from user where user_id != 1 and user_id != 2 and user_id != 3;

②、FIND_IN_SET函数用来比较是不是包含

FIND_IN_SET(str, strlist):str 要查询的字符串,strlist 字段名 参数以”,”分隔 如 (1,2,6,8)。如果 str 不在 strlist 或 strlist 为空字符串,则返回值为 0 。

select find_in_set('b','a,b,c'); //返回2

③、like 是广泛的模糊匹配,字符串中没有分隔符

select * from user where name like '%a%'
阅读 5

mysql文章
带到手机上看