56,675
社区成员
发帖
与我相关
我的任务
分享
select id, name, catid, listorder
from(
select a.*,
@v:=if(@g=a.id,
( select concat_ws(',', aa.id, aa.catid, aa.listorder) from tb aa where aa.id=@id),
concat_ws(',', a.id, a.catid, a.listorder)
) as _v,
@po:=concat(lpad(substring_index(@v, ',', -1), 4, '0'), if(@g=a.id,@po, '')) as _po,
@id:=substring_index(substring_index(@v, ',', 2), ',', -1) as _id,
@g:=a.id
from( select a.* from tb a, tb b order by a.id )a,
( select @po:='', @v:=null, @g:=null, @id:=null ) x
)id
where id._id = 0
order by _po