1. 按照層級查詢部門信息
? ? ? ? (1)部門表 department蹭劈,包含id茄茁、parent_id兩個(gè)字段
? ? ? ? (2)部門變量名: @departmentId
? ? ? ? (3)查詢字符串函數(shù): find_in_set(str, filterStr)
2. SQL
select
t1.department_id,
t1.parent_id,
case when find_in_set(parent_id, @depID) > 0?
then @depID := concat(@depID, ',', department_id)? ?
else 0 end as ischild
from
( select department_id, parent_id from department t order by parent_id, department_id ) t1,
( select @depID := {param}? ) t2
3. 查詢字段
? ??ischild = 0 時(shí)卿捎,為頂級部門香拉,其他為包含子部門Id