ソースコード
WITH ORDER_SUM AS (
SELECT DTL.ITEM_CODE,
MAX(OD.ORDER_DATE) AS ORDER_DATE,
SUM(DTL.ORDER_QTY) AS ORDER_QTY
FROM ORDERS OD
INNER JOIN ORDERS_DTL DTL
ON OD.ORDER_NO = DTL.ORDER_NO
WHERE OD.ORDER_DATE >= '2023-04-01'
AND OD.ORDER_DATE <= '2023-06-30'
GROUP BY DTL.ITEM_CODE
),RANKING AS (
SELECT IT.ITEM_CODE,
IT.ITEM_NAME,
OD.ORDER_DATE,
COALESCE(OD.ORDER_QTY,0) AS ORDER_QTY,
RANK()OVER(ORDER BY COALESCE(OD.ORDER_QTY,0) DESC,OD.ORDER_DATE DESC,IT.ITEM_CODE DESC) AS ITEM_POPULAR_RANK 
FROM ITEM IT
LEFT OUTER JOIN ORDER_SUM OD
ON IT.ITEM_CODE = OD.ITEM_CODE
)
SELECT ITEM_CODE,
ITEM_NAME,
ORDER_DATE,
ORDER_QTY,
CASE WHEN ORDER_QTY = 0 THEN 0
ELSE ITEM_POPULAR_RANK END AS ITEM_POPULAR_RANK
FROM RANKING
提出情報
提出日時2023/08/20 22:03:00
コンテスト第8回 SQLコンテスト
問題人気順位
受験者takahiro
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
77 MB
データパターン2
WA
78 MB