字段中元素精准匹配

如果系统中存储有,号分割的字段,可以使用FIND_IN_SET函数对每一个元素进行精确匹配,select pids from uums_organization where FIND_IN_SET(‘831’,PIDs);

select c.* from uums_user_details_info as c where c.ORG_NAME REGEXP '政治处|办公室’多个like时,推荐使用mysql的正则表达式。不推荐多个like使用or拼接。

根据指定字符截取指定位置的参数(SUBSTRING_INDEX)

select * from uums_organization where STATUS = 1 and id = (
select SUBSTRING_INDEX(t.PIDS,’,’, 1) as id from (SELECT PIDS FROM uums_organization where status = 1 and id = ‘831’) as t
)

猜你喜欢

转载自blog.csdn.net/weixin_44412272/article/details/120195637