ソースコード
WITH update_t AS(
    SELECT
        i_2404.ITEM_CODE
        , i_2404.ITEM_NAME
        , 'UPDATED' AS COMP_RSLT
        , i_2404.USER_UPDATE_DATETIME
    FROM
        ITEM i_2404
        , ITEM_HISTORY i_2312
    WHERE i_2404.ITEM_CODE = i_2312.ITEM_CODE
       AND i_2404.USER_UPDATE_DATETIME != i_2312.USER_UPDATE_DATETIME
    ORDER BY 1 DESC
), delete_t AS(
    SELECT
        ITEM_CODE
        , ITEM_NAME
        , 'DELETED' AS COMP_RSLT
    FROM
        ITEM_HISTORY i_2312
    WHERE NOT EXISTS(SELECT * FROM ITEM i_2404 WHERE i_2404.ITEM_CODE = i_2312.ITEM_CODE)
    ORDER BY 1 DESC
), add_t AS (
    SELECT
        ITEM_CODE
        , ITEM_NAME
        , 'ADDED' AS COMP_RSLT
    FROM
        ITEM i_2404
    WHERE NOT EXISTS(SELECT * FROM ITEM_HISTORY i_2312 WHERE i_2404.ITEM_CODE = i_2312.ITEM_CODE)
    ORDER BY 1 DESC
)
SELECT
    ITEM_CODE AS CODE
    , ITEM_NAME AS NAME
    , CASE
        WHEN delete_t.COMP_RSLT = 'DELETED'
            THEN 'DELETED'
        WHEN update_t.COMP_RSLT = 'UPDATED'
            THEN 'UPDATED'
        WHEN add_t.COMP_RSLT = 'ADDED'
            THEN 'ADDED'
    END AS COMP_RSLT
FROM
    update_t
    FULL OUTER JOIN delete_t USING(ITEM_CODE, ITEM_NAME)
    FULL OUTER JOIN add_t USING(ITEM_CODE, ITEM_NAME)
ORDER BY 1 DESC;
提出情報
提出日時2024/04/19 20:13:53
コンテスト第12回 SQLコンテスト
問題データ操作履歴
受験者1qaz2wsx3edc4rfv
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
83 MB
データパターン3
AC
84 MB