mysql 查询所有子节点】的更多相关文章

定义一个函数 ) CHARSET utf8 BEGIN ); ); SET sTemp = '$'; SET sTempChd =cast(rootId as CHAR); WHILE sTempChd is not null DO SET sTemp = concat(sTemp,',',sTempChd); ORDER BY sort, column_id; END WHILE; RETURN sTemp; END 使用: select t1.article_id, t1.sort,t1.s…
SELECT t3.college_code FROM ( SELECT t1.college_code, IF ( find_in_set( t1.parent_org_code, , ) AS ischild FROM ( ORDER BY parent_org_code, college_code ) t1, ( ' college_code ) t2 ) t3 WHERE t3.ischild != 0 表结构: t_college: id, college_code (机构编码), p…
前提:mysql  函数  find_in_set(str,strlist), cast(value as type)   一.find_in_set(str,strlist):如果字符串str是在的strlist组成的N子串的字符串列表,返回值的范围为1到N. 如果str不在strlist或strlist为空字符串,则返回值为 0 .如任意一个参数为NULL,则返回值为 NULL. 这个函数在第一个参数包含一个逗号(',')时将无法正常运行.   ①find_in_set(str,strlis…
1.所示案例数据表结构设计如下所示: 2.案例数据如下所示: 3.mysql查询语句可以查询出父级目录信息: 注意:自己的数据表表名称,切记手动修改,字段名称(特别注意id,parent_id字段名称,不然肯定查询不出来的). SELECT T2.* FROM ( SELECT @r AS _id, (SELECT @r := parent_id FROM catelog WHERE id = _id) AS parent_id, @l := @l + AS lvl FROM (SELECT @…
--表结构 CREATE TABLE `address` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code_value` varchar(32) DEFAULT NULL COMMENT '区域编码', `name` varchar(128) DEFAULT NULL COMMENT '区域名称', `remark` varchar(128) DEFAULT NULL COMMENT '说明', `pid` varchar(32) DEFAULT NUL…
每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code <!-- 查询机构的所有子机构 --> <select id="queryOrgEduAndChildrenForList" parameterType="java.util.Map" resultType="com.tianwen.springcloud.microservice.user.entity.OrgEdu&quo…
BEGIN DECLARE sChildList VARCHAR(4000); DECLARE sChildTemp VARCHAR(4000); SET sChildTemp =cast(rootId as CHAR); WHILE sChildTemp is not null DO IF (sChildList is not null) THEN SET sChildList = concat(sChildList,',',sChildTemp); ELSE SET sChildList =…
SELECT T2.* FROM ( SELECT @r AS _id, ( SELECT @r := parent_id FROM tp_module_rel WHERE REL_ID = _id ) AS parent_id, @l := @l + 1 AS lvl FROM (SELECT @r := 254, @l := 0) vars, tp_module_rel h WHERE @r <> 0 ) T1 JOIN tp_module_rel T2 ON T1._id = T2.re…
用CTE递归 ;with f as  ( select * from tab where id=1 union all select a.* from tab as a inner join f as b on a.pid=b.id ) select * from f…
;with cte as( select id,ParentCategoryId from Category where id = 17 union all select a.id,a.ParentCategoryId from Category a join cte b on a.ParentCategoryId = b.id where a.id is not null) select * from cte…