ソースコード
WITH SUB1 AS (
    SELECT
        MEMBER_CODE
        , ORDER_DATETIME
        , DATE(ORDER_DATETIME) AS ORDER_DATE
        , DATE(LAG(ORDER_DATETIME) OVER (PARTITION BY MEMBER_CODE)) AS ORDER_DATE_BFR
    FROM
        EC_ORDERS
),
SUB2 AS (
    SELECT
        MEMBER_CODE
        , ROW_NUMBER() OVER (PARTITION BY MEMBER_CODE) AS RNUM
        , ORDER_DATETIME
        , CASE WHEN ORDER_DATE_BFR IS NULL THEN -1 ELSE JULIANDAY(ORDER_DATE) - JULIANDAY(ORDER_DATE_BFR) END AS KEIKA
    FROM 
        SUB1
    WHERE
        ORDER_DATE BETWEEN '2023-07-01' AND '2023-07-31'
)
SELECT
    ORDER_DATETIME AS ORDER_DATE
    , a.MEMBER_CODE AS CODE
    , CASE b.OPTOUT_TYPE WHEN 0 THEN '可' WHEN 1 THEN '不可' ELSE '不明' END
FROM
    SUB2 a
    INNER JOIN MEMBER_MST b ON
        a.MEMBER_CODE = b.MEMBER_CODE
WHERE
    RNUM = 1
    AND KEIKA > 365
ORDER BY
    ORDER_DATETIME DESC
    , a.MEMBER_CODE DESC
;
提出情報
提出日時2024/02/13 14:17:30
コンテスト第9回 SQLコンテスト
問題クーポン配布対象
受験者SQL2022
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
85 MB
データパターン2
WA
85 MB