-- display_name NZ分部所有用户
SELECT user_code,display_name FROM scy_user WHERE ou_id=1627 AND is_deleted=0
-- NZ第二分部下用户
SELECT user_code,display_name FROM scy_user WHERE ou_id=1629 AND is_deleted=0
-- NZ分部下所有店铺关联职员及关联用户 d.display_name,c.employee_name,a.shop_name,a.shop_code
SELECT d.`user_code`,d.`display_name`,d.`employee_name`,a.`shop_name` FROM bas_shop a
LEFT JOIN
bas_employee_shop b ON a.id = b.shop_id
LEFT JOIN
bas_employee c ON b.employee_id =c.id
LEFT JOIN
scy_user d ON c.id = d.employee_id
WHERE
a.ou_id=1627 AND a.is_deleted=0 AND b.is_deleted=0 AND c.is_deleted=0
SELECT * FROM bas_shop WHERE ou_id=1627 AND is_deleted=0
SELECT * FROM bas_employee_shop WHERE ou_id=1627 AND is_deleted=0
SELECT * FROM bas_employee WHERE is_deleted=0 AND group_id=61
SELECT employee_id FROM scy_user WHERE ou_id=1627 AND is_deleted=0
-- NZ第二分部下所有店铺关联职员及关联用户
SELECT * FROM bas_shop a
LEFT JOIN
bas_employee_shop b ON a.id = b.shop_id
LEFT JOIN
bas_employee c ON b.employee_id =c.id
LEFT JOIN
scy_user d ON c.id = d.employee_id
WHERE
a.ou_id=1629 AND a.is_deleted=0 AND b.is_deleted=0 AND c.is_deleted=0
-- NZ分部下单个店铺关联职员及关联用户
SELECT * FROM bas_shop a
LEFT JOIN
bas_employee_shop b ON a.id = b.shop_id
LEFT JOIN
bas_employee c ON b.employee_id =c.id
LEFT JOIN
scy_user d ON c.id = d.employee_id
WHERE
a.ou_id=1627 AND a.is_deleted=0 AND b.is_deleted=0 AND c.is_deleted=0 AND shop_name='华西总店'
-- NZ分部下所有部门关联职员及关联用户
SELECT a.user_code,a.display_name,a.employee_name,d.dept_name FROM scy_user a
LEFT JOIN
bas_employee b ON a.employee_id = b.id
LEFT JOIN
bas_employee_dept c ON b.id=c.employee_id
LEFT JOIN
bas_dept d ON c.dept_id = d.id
WHERE
a.ou_id=1627 AND a.is_deleted=0
-- NZ第二分部下所有部门关联职员及关联用户
SELECT a.display_name,a.employee_name,d.dept_name FROM scy_user a
LEFT JOIN
bas_employee b ON a.employee_id = b.id
LEFT JOIN
bas_employee_dept c ON b.id=c.employee_id
LEFT JOIN
bas_dept d ON c.dept_id = d.id
WHERE
a.group_id=1629 AND a.is_deleted=0