mysql COALESCE用法 ,GROUP_CONCAT分组用法

sdroot.dept_name company,
        COALESCE(
        (case when sd5.dept_name = sdroot.dept_name then null else sd5.dept_name end) ,
        (case when sd4.dept_name in(sdroot.dept_name,sd5.dept_name)  then null else sd4.dept_name end) ,
        (case when sd3.dept_name in(sdroot.dept_name,sd4.dept_name) then null else sd3.dept_name end) ,
        (case when sd2.dept_name in(sdroot.dept_name,sd3.dept_name,sd4.dept_name)  then null else sd2.dept_name end) ,
        (case when sd1.dept_name in(sdroot.dept_name,sd3.dept_name,sd2.dept_name,sd3.dept_name,sd4.dept_name) then null else sd1.dept_name end)) deptName0,
        COALESCE(
        (case when sd1.order_num = '3' and sd1.dept_name is not Null then sd1.dept_name  end) ,
        (case when sd2.order_num = '3' and sd2.dept_name is not Null then sd2.dept_name  end) ,
        (case when sd3.order_num = '3' and sd3.dept_name is not Null then sd3.dept_name  end) ,
        (case when sd4.order_num = '3'and sd4.dept_name is not Null then sd4.dept_name  end)
        ) deptName1,

        coalesce(
        (case when sd1.order_num = '4' and sd1.dept_name is not Null then sd1.dept_name end) ,
        (case when sd2.order_num = '4' and sd2.dept_name is not Null then sd2.dept_name  end) ,
        (case when sd3.order_num = '4' and sd3.dept_name is not Null then sd3.dept_name end) ,
        (case when sd4.order_num = '4' and sd4.dept_name is not Null then sd4.dept_name  end)
        ) deptName2,

        coalesce(
        (case when sd1.order_num = '5' and sd1.dept_name is not Null then sd1.dept_name end) ,
        (case when sd2.order_num = '5' and sd2.dept_name is not Null then sd2.dept_name  end) ,
        (case when sd3.order_num = '5' and sd3.dept_name is not Null then sd3.dept_name end) ,
        (case when sd4.order_num = '5' and sd4.dept_name is not Null then sd4.dept_name  end) ,
        (case when sd5.order_num = '5' and sd5.dept_name is not Null then sd5.dept_name  end)
        ) deptName3,
        sd.dept_name deptName,
        (select GROUP_CONCAT(c.dept_name ORDER BY c.dept_id asc) as deptNameAll  from sys_dept c where find_in_set (c.dept_id ,sd.ancestors)) as deptNameAll,

  

posted @ 2023-08-30 13:54  A汉克先生  阅读(40)  评论(0编辑  收藏  举报