自关联?
多级评论
多级菜单
建表
MySQL [tree]> create table node_tree (id int not null primary key,node_name varchar(128) not null default "",up_node_id int,node_level char(1));
MySQL [tree]> insert into node_tree values (1,"jx",null,"1"),(2,'jx.webserver', 1, '2'),(3,'jx.webserver.nginx1', 2, '3'),(4,'jx.logserver', 1, '2');
查询jx的从表
MySQL [tree]> select nt.node_name from node_tree,node_tree as nt where node_tree.node_name="jx" and node_tree.id=nt.up_node_id;
MySQL [tree]> select
-> node_tree1.id as 主表ID,
-> node_tree1.name as 主表名字,
-> node_tree2.name as 从表名字,
-> node_tree2.up_id as 从表上级ID
->
-> from node_tree1, node_tree2
->
-> where node_tree1.name='jx' and node_tree1.id= node_tree2.up_id;
查询jx.webserver的主表
MySQL [tree]> select a.node_name from node_tree a ,node_tree b where b.node_name="jx.webserver" and b.up_node_id=a.id;