一个客户名下有多个业务员在跟,而一个业务员,又可以同时属于多个部门 需求:某个部门下的业务员,不能继续跟进客户.
直接上代码:
SELECT distinct ci.id
from b_customer_info ci
left join b_customer_salesman cs on ci.id = cs.customer_id
left JOIN b_tenant_employee te ON te.user_id = cs.salesman
where concat( te.org_id COLLATE utf8mb4_general_ci, ‘,’) REGEXP concat(replace((SELECT GROUP_CONCAT(distinct id) from t_s_org where is_big = true group by is_big) COLLATE utf8mb4_general_ci, ‘,’, ‘,|’), ‘,’) = 1
最核心的判断就是where条件中,用正则判断多对多是否包含即可