-- ======================================
-- 年龄分布
-- ======================================

SELECT
nld
,sum(sl) AS sl
FROM
(
SELECT
zb	    -- 总部
,pq	    -- 片区
,xm	    -- 项目
,nld	--	年龄段
,sl	    --	数量
FROM ods_hr_view_nld_d
)A
LEFT JOIN
(
    SELECT
        organ_code
         ,hr_organ_id
         ,hr_comm_id
    FROM dim_organ_mapping_kunan_tmp
    GROUP BY
    organ_code
    ,hr_organ_id
    ,hr_comm_id

)B
ON A.pq = B.hr_organ_id
 and A.xm = b.hr_comm_id
where 1 = 1
    ${IF(LEN(p_area)>0," AND B.organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")}
GROUP BY nld



-- ======================================
-- 司龄分布
-- ======================================

SELECT
    sld
     ,sum(sl) AS sl
FROM
    (
        SELECT
            zb	    -- 总部
             ,pq	    -- 片区
             ,xm	    -- 项目
             ,sld	--	司龄段
             ,sl	    --	数量
        FROM ods_hr_view_sld_d
    )A
        LEFT JOIN
    (
        SELECT
            organ_code
             ,hr_organ_id
             ,hr_comm_id
        FROM dim_organ_mapping_kunan_tmp
        GROUP BY
            organ_code
               ,hr_organ_id
               ,hr_comm_id

    )B
    ON A.pq = B.hr_organ_id
        and A.xm = b.hr_comm_id
where 1 = 1
    ${IF(LEN(p_area)>0," AND B.organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")}
GROUP BY sld





-- ======================================
-- 学历分布
-- ======================================


SELECT
    xl
     ,sum(sl) AS sl
FROM
    (
        SELECT
            zb	    -- 总部
             ,pq	    -- 片区
             ,xm	    -- 项目
             ,xl	--	学历
             ,sl	    --	数量
        FROM ods_hr_view_xl_d
    )A
        LEFT JOIN
    (
        SELECT
            organ_code
             ,hr_organ_id
             ,hr_comm_id
        FROM dim_organ_mapping_kunan_tmp
        GROUP BY
            organ_code
               ,hr_organ_id
               ,hr_comm_id

    )B
    ON A.pq = B.hr_organ_id
        and A.xm = b.hr_comm_id
where 1 = 1
    ${IF(LEN(p_area)>0," AND B.organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")}
GROUP BY xl



-- ======================================
-- 职务角色
-- ======================================


SELECT
    zwje
     ,sum(sl) AS sl
FROM
    (
        SELECT
            zb	    -- 总部
             ,pq	    -- 片区
             ,xm	    -- 项目
             ,zwje	--	职务角色
             ,sl	    --	数量
        FROM dw.ods_hr_view_zwjs_d
    )A
        LEFT JOIN
    (
        SELECT
            organ_code
             ,hr_organ_id
             ,hr_comm_id
        FROM dim_organ_mapping_kunan_tmp
        GROUP BY
            organ_code
               ,hr_organ_id
               ,hr_comm_id

    )B
    ON A.pq = B.hr_organ_id
        and A.xm = b.hr_comm_id
where 1 = 1
    ${IF(LEN(p_area)>0," AND B.organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")}
GROUP BY zwje






-- ======================================
-- 职务层级
-- ======================================


SELECT
    swtx
     ,sum(sl) AS sl
FROM
    (
        SELECT
            zb	    -- 总部
             ,pq	    -- 片区
             ,xm	    -- 项目
             ,swtx	--	职务层级
             ,sl	    --	数量
        FROM dw.ods_hr_view_swtx_d
    )A
        LEFT JOIN
    (
        SELECT
            organ_code
             ,hr_organ_id
             ,hr_comm_id
        FROM dim_organ_mapping_kunan_tmp
        GROUP BY
            organ_code
               ,hr_organ_id
               ,hr_comm_id

    )B
    ON A.pq = B.hr_organ_id
        and A.xm = b.hr_comm_id
where 1 = 1
    ${IF(LEN(p_area)>0," AND B.organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")}
GROUP BY swtx





-- ======================================
-- 一级专业条线
-- ======================================


SELECT
    zytx
     ,sum(sl) AS sl
FROM
    (
        SELECT
            zb	    -- 总部
             ,pq	    -- 片区
             ,xm	    -- 项目
             ,zytx	--	一级专业条线
             ,sl	    --	数量
        FROM dw.ods_hr_view_zytx_d
    )A
        LEFT JOIN
    (
        SELECT
            organ_code
             ,hr_organ_id
             ,hr_comm_id
        FROM dim_organ_mapping_kunan_tmp
        GROUP BY
            organ_code
               ,hr_organ_id
               ,hr_comm_id

    )B
    ON A.pq = B.hr_organ_id
        and A.xm = b.hr_comm_id
where 1 = 1
    ${IF(LEN(p_area)>0," AND B.organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")}
GROUP BY zytx



