ソースコード
WITH UPDATE_ITEMS AS (
    SELECT
        ITEM.ITEM_CODE
        , ITEM.ITEM_NAME
        , 'UPDATED' AS COMP_RSLT
    FROM
        ITEM
    INNER JOIN
        ITEM_HISTORY ON ITEM.ITEM_CODE = ITEM_HISTORY.ITEM_CODE
    WHERE
        ITEM.USER_UPDATE_DATETIME != ITEM_HISTORY.USER_UPDATE_DATETIME
)
, ADDED_ITEMS AS (
    SELECT
        ITEM.ITEM_CODE
        , ITEM.ITEM_NAME
        , 'ADDED' AS COMP_RSLT
    FROM
        ITEM
    WHERE
        ITEM.ITEM_CODE NOT IN (
            SELECT
                ITEM_HISTORY.ITEM_CODE
            FROM
                ITEM_HISTORY
        ) 
)
, DELETED_ITEMS AS (
    SELECT
        ITEM_HISTORY.ITEM_CODE
        , ITEM_HISTORY.ITEM_NAME
        , 'DELETED' AS COMP_RSLT
    FROM
        ITEM_HISTORY
    WHERE
        ITEM_HISTORY.ITEM_CODE NOT IN (
            SELECT
                ITEM.ITEM_CODE
            FROM
                ITEM
        ) 
)
SELECT
    *
FROM (
    SELECT ITEM_CODE AS CODE, ITEM_NAME AS NAME, COMP_RSLT FROM UPDATE_ITEMS
    UNION ALL
    SELECT ITEM_CODE AS CODE, ITEM_NAME AS NAME, COMP_RSLT FROM ADDED_ITEMS
    UNION ALL
    SELECT ITEM_CODE AS CODE, ITEM_NAME AS NAME, COMP_RSLT FROM DELETED_ITEMS
)
ORDER BY 
    CODE DESC
;
提出情報
提出日時2024/04/22 10:08:21
コンテスト第12回 SQLコンテスト
問題データ操作履歴
受験者maori
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
83 MB
データパターン2
AC
86 MB
データパターン3
AC
86 MB