[SQL] 纯文本查看 复制代码 select a.name as 名称,
(case
when a.treelevel = 0 then a.id
when a.treelevel = 1 then a.parentid
when a.treelevel = 2 then (select b.parentid from m_class b where a.parentid = b.id)
when a.treelevel = 3 then (select c.parentid from m_class c where c.id= (select b.parentid from m_class b where a.parentid = b.id))
else ''
end) as 根,
(case
when a.treelevel = 0 then ''
when a.treelevel = 1 then a.id
when a.treelevel = 2 then a.parentid
when a.treelevel = 3 then (select b.parentid from m_class b where a.parentid = b.id)
else ''
end) as 一级,
(case
when a.treelevel = 0 then ''
when a.treelevel = 1 then ''
when a.treelevel = 2 then a.id
when a.treelevel = 3 then a.parentid
else ''
end) as 二级,
(case
when a.treelevel = 0 then ''
when a.treelevel = 1 then ''
when a.treelevel = 2 then ''
when a.treelevel = 3 then a.id
else ''
end) as 三级
from m_class a |