定义一个函数 ) 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…
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 @…
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 =…
;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…