部门及子部门查询

CREATE TABLE sys_dept (
id bigint NOT NULL COMMENT ‘ID’,
parent_id bigint NOT NULL COMMENT ‘父级部门ID’,
name varchar(64) NOT NULL COMMENT ‘名称’,
full_name varchar(512) NOT NULL COMMENT ‘全名’,
full_id varchar(512) DEFAULT ‘’ COMMENT ‘部门全路径id’,
level int NOT NULL COMMENT ‘层级’,
PRIMARY KEY (id),
KEY idx_sys_dept_leader_id (leader_id) USING BTREE,
KEY idx_sys_dept_sync_target_parent_code (sync_target_parent_code),
KEY idx_sys_dept_parent_id (parent_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT=‘部门’

CREATE TABLE sys_dept_scope (
parent_dept_id bigint NOT NULL COMMENT ‘父级部门ID’,
children_dept_id bigint NOT NULL COMMENT ‘子级部门ID’,
parent_dept_level smallint DEFAULT NULL COMMENT ‘父级部门层级’,
children_dept_level smallint DEFAULT NULL COMMENT ‘子级部门层级’,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间’,
PRIMARY KEY (parent_dept_id,children_dept_id),
KEY idx_sys_dept_scope_children_dept_id (children_dept_id,parent_dept_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT=‘部门关联范围’

select
*
from
sys_dept sd
where
exists(
select
1
from
sys_dept_scope sdc
where
sdc.parent_dept_id in (516238236490661888)
and sdc.children_dept_id = sd.id
limit 1
)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值