ソースコード
DELETE FROM ITEM
WHERE
    ITEM_CODE IN (
        SELECT
            ITEM_ITEM_CODE
        FROM
        (
            SELECT
            	*
            FROM(
            		SELECT
            			t1.ITEM_CODE AS ITEM_ITEM_CODE,
            			t1.ITEM_NAME,
            			MAX(COALESCE(t2.LAST_DELIVERY_DATE, '9999-12-31')) OVER (PARTITION BY t2.ITEM_CODE,t2.WH_CODE) AS max_LAST_DELIVERY_DATE
            			,CASE
            				WHEN MAX(COALESCE(t2.LAST_DELIVERY_DATE, '9999-12-31')) OVER (PARTITION BY t2.ITEM_CODE,t2.WH_CODE) = LAST_DELIVERY_DATE THEN
            					t2.ACTUAL_AMT
            				ELSE
            					NULL
            			END AS LAST_ACTUAL_AMT,
            			t2.ACTUAL_AMT,
            			t2.WH_CODE,
            			t2.ITEM_CODE,
            			t2.STOCK_TYPE,
            			t2.QUALITY_TYPE
            		FROM
            			ITEM t1
            		LEFT OUTER JOIN	STOCK t2
            		ON t1.ITEM_CODE = t2.ITEM_CODE
            		WHERE
            			t1.STOCK_MANAGEMENT_TYPE = 1
            )T
            WHERE
                max_LAST_DELIVERY_DATE < '2023-01-01'
            	OR 
            	(
            			WH_CODE IS NULL
            		AND ITEM_CODE IS NULL
            		AND STOCK_TYPE IS NULL
            		AND QUALITY_TYPE IS NULL
            	)
            )TT
        GROUP BY ITEM_ITEM_CODE
        HAVING max(LAST_ACTUAL_AMT) = 0 OR WH_CODE IS NULL
    );
提出情報
提出日時2023/06/17 23:30:48
コンテスト第7回 SQLコンテスト
問題商品整理
受験者kkinjoh
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量76 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
76 MB
データパターン2
WA
76 MB