Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.1 kB
2
Indexable
Never
WITH base_skp_organisasi AS (
    SELECT so.id AS bso_id, u.id as unor_id, rhk.deskripsi AS deskripsi, u.unit AS unor_nama, rhk.jenis AS jenis_rhk , rhk.id as rhk_id, u.is_tim_kerja
    FROM skp_organisasi so
    INNER JOIN skp_organisasi_rhk rhk ON so.id=rhk.skp_organisasi_id
    INNER JOIN unor u ON so.unor_id = u.id
    WHERE
        so.id IN ('d6fa48d9c5974d109c3e18bc8b6ceac5')
        AND so.deleted_at IS NULL AND rhk.deleted_at IS NULL AND u.deleted_at IS NULL
) 
    SELECT 
        'indikator' AS jenis, 
        ind.id AS id, 
        ind.deskripsi AS deskripsi, 
        bso.deskripsi AS rhk, 
        bso.unor_nama, 
        bso.jenis_rhk
    FROM base_skp_organisasi bso
    INNER JOIN skp_organisasi_indikator ind ON bso.rhk_id = ind.skp_organisasi_rhk_id AND  ind.deleted_at IS NULL
    WHERE
        bso.is_tim_kerja != '1'
UNION
    SELECT 
        'rhk' AS jenis, 
        rhk_id AS id, 
        bso.deskripsi, 
        bso.deskripsi AS rhk, 
        bso.unor_nama,
        bso.jenis_rhk 
    FROM base_skp_organisasi bso
    WHERE
        bso.is_tim_kerja = '1';

///
SELECT
    'indikator' AS jenis, ind.id AS id, ind.deskripsi AS deskripsi, rhk.deskripsi AS rhk, u.unit AS unor_nama, rhk.jenis AS jenis_rhk
FROM skp_organisasi s
INNER JOIN skp_organisasi_rhk rhk ON s.id=rhk.skp_organisasi_id
INNER JOIN skp_organisasi_indikator ind ON rhk.id=ind.skp_organisasi_rhk_id
INNER JOIN unor u ON s.unor_id = u.id
WHERE
    s.id IN ('d6fa48d9c5974d109c3e18bc8b6ceac5')
    AND u.is_tim_kerja != '1'
    AND s.deleted_at IS NULL AND rhk.deleted_at IS NULL AND ind.deleted_at IS NULL AND u.deleted_at IS NULL
UNION
SELECT
    'rhk' AS jenis, rhk.id AS id, rhk.deskripsi AS deskripsi, rhk.deskripsi AS rhk, u.unit AS unor_nama, rhk.jenis AS jenis_rhk
FROM skp_organisasi s
INNER JOIN unor u ON s.unor_id = u.id
INNER JOIN skp_organisasi_rhk rhk ON s.id = rhk.skp_organisasi_id
WHERE
    s.id IN ('d6fa48d9c5974d109c3e18bc8b6ceac5')
    AND u.is_tim_kerja = '1'
    AND s.deleted_at IS NULL
    AND rhk.deleted_at IS NULL
    AND u.deleted_at IS NULL
Leave a Comment