In the tree structure table, obtain all parent node paths of the specified node.

Source: Internet
Author: User
In the tree structure table, retrieve all parent node paths of the specified node. For ease of viewing, I added the node id. No droptableifexists 'group'; createtable 'group' ('id' int (11) notnullauto_increment, 'parent _ group_id 'int (11) notnulldefault-1, 'name' varchar (255) not

In the tree structure table, retrieve all parent node paths of the specified node. For ease of viewing, I added the node id. No drop table if exists 'group'; create table 'group' ('id' int (11) not null auto_increment, 'parent _ group_id 'int (11) not null default '-1', 'name' varchar (255) not

In the tree structure table, retrieve all parent node paths of the specified node. For ease of viewing, I added the node id.
<无>
Drop table if exists 'group'; create table 'group' ('id' int (11) not null auto_increment, 'parent _ group_id 'int (11) not null default '-1', 'name' varchar (255) not null, primary key ('id'); insert into 'group' ('id ', 'name', 'parent _ group_id ') values (1, 'A',-1); insert into 'group' ('id', 'name ', 'parent _ group_id ') values (2,' B ',-1); insert into 'group' ('id', 'name', 'parent _ group_id ') values (3, 'C' , 1);/*** return the parent node path of the specified node in the tree structure table. * zhanglu Bing zhanglubing927@163.com * 2012-2-21 */drop procedure if exists get_path; delimiter $ create procedure get_path (in id int) begindeclare gid int default id; declare path varchar (255) default ''; while gid is not null and gid! =-1 doselect concat (g. name, '(', g. id, '),'-', path), g. parent_group_id into path, gid from 'group' g where g. id = gid; end while; select substring (path, 1, length (path)-1) 'path'; end $ -- call get_path (3); -- a (1) -c (3)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.