ソースコード
SELECT 
CODE,
NAME,
CASE WHEN UPDATE_FLAG = 1 THEN 'UPDATED'
     WHEN ADD_FLAG = 1 THEN 'ADDED'
     WHEN DELETED_FLAG = 1 THEN 'DELETED'
     END AS COMP_RSLT
FROM (
SELECT
L.ITEM_CODE AS CODE
,L.ITEM_NAME AS NAME
,0 AS DELETED_FLAG
,CASE WHEN L.USER_UPDATE_DATETIME != R.USER_UPDATE_DATETIME THEN 1 ELSE 0 END AS UPDATE_FLAG
,CASE WHEN L.ITEM_CODE IS NOT NULL AND R.ITEM_CODE IS NULL THEN 1 ELSE 0 END AS ADD_FLAG
FROM ITEM L
LEFT JOIN ITEM_HISTORY R
ON L.ITEM_CODE = R.ITEM_CODE 
WHERE UPDATE_FLAG = 1 OR ADD_FLAG = 1
UNION ALL 
SELECT 
L.ITEM_CODE AS CODE
,L.ITEM_NAME AS NAME
,CASE WHEN L.ITEM_CODE IS NOT NULL AND R.ITEM_CODE IS NULL THEN 1 ELSE 0 END AS DELETE_FLAG
,0 AS UPDATE_FLAG
,0 AS ADD_FLAG
FROM ITEM_HISTORY L
LEFT JOIN ITEM R
ON L.ITEM_CODE = R.ITEM_CODE 
WHERE DELETE_FLAG = 1
)
ORDER BY 1 DESC
提出情報
提出日時2024/04/21 19:39:02
コンテスト第12回 SQLコンテスト
問題データ操作履歴
受験者yukio
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
85 MB
データパターン3
AC
85 MB