- 在
mysql
中构建函数
BEGIN
DECLARE str varchar(100);
DECLARE cid varchar(100);
SET str = '$';
SET cid = rootId;
WHILE cid is not null DO
SET str = concat(str, ',', cid);
SELECT group_concat(id) INTO cid FROM depts where FIND_IN_SET(parent_id, cid) > 0;
END WHILE;
RETURN str;
END
- 查询语句
select * from users where dept_id in (select id from depts d where FIND_IN_SET(id,getChildList(1)));
- 还是附上完整的
sql
文件带劲
链接: https://pan.baidu.com/s/1SXGLFdUwPQbyS3le4O81-A 密码: 9zw8
刚刚深入点去接触 MySql
,以前的我对数据库的理解真是太天真了。
参照链接:https://blog.csdn.net/u014033756/article/details/70567746