select
    left(a.start_date,7) ym
     , b.subcompanyid1 subcompanyid
     , c.subcompanyname
     , c.supsubcomid
     , a.plan_level
     , count(*) plan_num
     , count(plan_name) plan_adjust_num
     , sum(case when plan_status = 2 then 1 else 0 end) plan_cancel_num
     , sum(case when plan_status = 6 then 1 else 0 end) plan_exempt_assess_num
     , sum(case when plan_status = 4 then 1 else 0 end) plan_incomplete_num
     , sum(case when left(start_date,7) = left(input_date,7) then 1 else 0 end) plan_thism_num
     , sum(case when plan_status = 0 then 1 else 0 end) plan_in_progress_num
     , sum(case when plan_status = 1 then 1 else 0 end) plan_complete_num
from (
         SELECT
             concat(left(trim(start_date),5),lpad(substring_index(substring_index(trim(start_date),'-',2),'-',-1),2,0),right(trim(start_date),3)) start_date,
             a.plan_level,
             jt.responsible_person1 ,
             a.id,
             a.plan_status,
             a.input_date,
             a.end_date
         FROM dwd_operations_plan_info_d a,
              JSON_TABLE (
                      cast( CONCAT( '["', REPLACE ( responsible_person1, ',', '","' ), '"]' ) AS json ),
                      "$[*]" COLUMNS ( responsible_person1 INT PATH "$" )
              ) AS jt
     ) a
         left join ods_oa_hrmresource_d b
                   on a.responsible_person1 = b.id
         inner join ods_oa_hrmsubcompany_d c
                    on b.subcompanyid1 = c.id
         left join (select distinct plan_name from dwd_operations_plan_adjust_info_d) d
                   on a.id = d.plan_name
group by
    left(a.start_date,7)
       , b.subcompanyid1
       , c.subcompanyname
       , c.supsubcomid
       , a.plan_level