ソースコード
WITH T_added AS ( 
    -- 追加分
    SELECT
         ITEM.ITEM_CODE AS CODE
        ,ITEM.ITEM_NAME AS NAME
        ,ITEM.USER_UPDATE_DATETIME AS it
        ,ITEM_HISTORY.USER_UPDATE_DATETIME as it_h
        ,'ADDED' AS COMP_RSLT
    FROM
        ITEM
        LEFT JOIN ITEM_HISTORY ON ITEM_HISTORY.ITEM_CODE = ITEM.ITEM_CODE
    WHERE
        ITEM_HISTORY.ITEM_CODE is NULL 
) 
,T_deleted AS ( 
    -- 削除分
    SELECT
         ITEM_HISTORY.ITEM_CODE AS CODE
        ,ITEM_HISTORY.ITEM_NAME AS NAME
        ,ITEM.USER_UPDATE_DATETIME as it
        ,ITEM_HISTORY.USER_UPDATE_DATETIME as it_h
        , 'DELETED'  AS COMP_RSLT
    FROM
        ITEM_HISTORY
        LEFT JOIN ITEM ON ITEM_HISTORY.ITEM_CODE = ITEM.ITEM_CODE
    WHERE
        ITEM.ITEM_CODE is NULL 
) 
,T_updated AS ( 
    -- 更新分
    SELECT
         ITEM.ITEM_CODE AS CODE
        ,ITEM.ITEM_NAME AS NAME
        ,ITEM.USER_UPDATE_DATETIME as it
        ,ITEM_HISTORY.USER_UPDATE_DATETIME as it_h
        , 'UPDATED' AS COMP_RSLT
    FROM
        ITEM
        LEFT JOIN ITEM_HISTORY ON ITEM_HISTORY.ITEM_CODE = ITEM.ITEM_CODE
    WHERE
        ITEM.USER_UPDATE_DATETIME <> ITEM_HISTORY.USER_UPDATE_DATETIME
) 

SELECT
      Ta.CODE AS CODE
    , Ta.NAME AS NAME
--    ,Ta.it as it
    ,Ta.COMP_RSLT as COMP_RSLT
FROM
    T_added as Ta
union
SELECT
      Td.CODE AS CODE
    , Td.NAME AS NAME
--    ,Td.it as it
    ,Td.COMP_RSLT as COMP_RSLT
FROM
    T_deleted as Td
union
SELECT
      Tu.CODE as CODE
    , Tu.NAME as NAME
--    ,Tu.it as it
    ,Tu.COMP_RSLT as COMP_RSLT
FROM
    T_updated as Tu
    
ORDER BY
        CODE deSC
;
提出情報
提出日時2024/04/19 17:13:46
コンテスト第12回 SQLコンテスト
問題データ操作履歴
受験者teiteitoutou
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
85 MB
データパターン3
AC
83 MB