select
    left(a.end_date,7) ym
     , b.subcompanyid1 subcompanyid
     , c.subcompanyname
     , c.supsubcomid
     , a.plan_level
    ,a.plan_name
,a.id
,a.responsible_person1
,organ_code, organ_name, comm_id, comm_name
     , oa_organ_code, oa_organ_name, oa_comm_id, oa_comm_name
 --    , 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 = 7 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,plan_name,
             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
             where  a.id in ('17015','17016','17024','17056','17075','17084','29372','29373','29374','29375','29376','29377','29433','29434','29435','29436','29437','29438','29439','29440','29503','29504','29505','29506','29507','29508','29509','29510','29561','29562','29564','29565','29566','29567','29568','29569','29591','29629','29630','40703','42177','42180','42767','42779','42837')

     ) 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
         left join (select distinct organ_code, organ_name, comm_id, comm_name
                                  , oa_organ_code, oa_organ_name, oa_comm_id, oa_comm_name from dim_organ_mapping where comm_id is not null) b1
                   on b.subcompanyid1 = b1.oa_comm_id

WHERE left(a.end_date,7) = '2024-10'

-- AND b.subcompanyid1 in(select distinct  oa_comm_id  from dim_organ_mapping where comm_id is not null and organ_code = '0108')
-- group by
--     left(a.end_date,7)
--        , b.subcompanyid1
--        , c.subcompanyname
--        , c.supsubcomid
--        , a.plan_level