ソースコード
WITH OrderedItems AS (
  SELECT
    ITEM.ITEM_CODE,
    ITEM.ITEM_NAME,
    SUM(ORDERS_DTL.ORDER_QTY) AS TotalOrderQty,
    MAX(ORDERS.ORDER_DATE) AS LatestOrderDate
  FROM ITEM
  LEFT JOIN ORDERS_DTL ON ITEM.ITEM_CODE = ORDERS_DTL.ITEM_CODE
  LEFT JOIN ORDERS ON ORDERS_DTL.ORDER_NO = ORDERS.ORDER_NO
    AND ORDERS.ORDER_DATE BETWEEN '2023-04-01' AND '2023-06-30'
  GROUP BY ITEM.ITEM_CODE
),
Ranking AS (
  SELECT
    ITEM_CODE,
    ITEM_NAME,
    TotalOrderQty,
    LatestOrderDate,
    CASE WHEN TotalOrderQty IS NULL OR TotalOrderQty = 0 THEN 0
         ELSE ROW_NUMBER() OVER (
           ORDER BY TotalOrderQty DESC, LatestOrderDate DESC, ITEM_CODE DESC
         )
    END AS ITEM_POPULAR_RANK
  FROM OrderedItems
)
SELECT ITEM_CODE,ITEM_NAME,ITEM_POPULAR_RANK FROM Ranking;
提出情報
提出日時2024/03/21 08:57:02
コンテスト第8回 SQLコンテスト
問題人気順位
受験者doro
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量83 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
83 MB
データパターン2
WA
83 MB