2023-05-04_2.sql 1.4 KB
-- 更新staff_assess
WITH t_staff_assess AS (
    SELECT
        *
    FROM
        staff_assess
    WHERE
        1 = 1
        AND cycle_id = 1653724699349225472
        AND NOT EXISTS (
            SELECT
                *
            FROM
                staff_assess_content
            WHERE
                staff_assess_content.staff_assess_id = staff_assess.id))
UPDATE
    staff_assess
SET
    deleted_at = now()
WHERE
    1 = 1
    AND staff_assess.id IN (
        SELECT
            id
        FROM
            t_staff_assess);

-- 更新staff_assess
WITH t_staff_assess AS (
    SELECT
        row_number() OVER (PARTITION BY evaluation_project_id,
            "types",
            staff_assess.begin_time) AS row_id,
        *
    FROM
        staff_assess
    WHERE
        1 = 1
        AND cycle_id = 1653724699349225472
        AND NOT EXISTS (
            SELECT
                *
            FROM
                staff_assess_content
            WHERE
                staff_assess_content.staff_assess_id = staff_assess.id)
),
t_staff_assess_2 AS (
    SELECT
        *
    FROM
        t_staff_assess
    WHERE
        row_id = 1)
UPDATE
    staff_assess
SET
    deleted_at = NULL
WHERE
    1 = 1
    AND cycle_id = 1653724699349225472
    AND staff_assess.id IN (
        SELECT
            id
        FROM
            t_staff_assess_2);

;

UPDATE
    staff_assess
SET
    deleted_at = now()
WHERE
    id IN (18404, 18458);