34,587
社区成员
发帖
与我相关
我的任务
分享
create table tb(id int,name varchar(20),PID int,c int)
insert into tb select 1,'中国',null,0
insert into tb select 2,'广东',1,1
insert into tb select 3,'深圳',2,2
insert into tb select 4,'河北',1,1
insert into tb select 5,'秦皇岛',4,2
insert into tb select 6,'山海关',5,3
select one.name as '第一级',two.name as '第二级',thr.name as '第三级',fou.name as '第四级' from
(select * from tb where c=0) one left join
(select * from tb where c=1) two on one.id=two.pid left join
(select * from tb where c=2) thr on two.id=thr.pid left join
(select * from tb where c=3) fou on thr.id=fou.pid