ソースコード
WITH MEMBERS_2023_JULY_ORDER AS (
    SELECT A.MEMBER_CODE AS CODE, MIN(ORDER_DATETIME) AS ORDER_DATETIME
    FROM MEMBER_MST AS A INNER JOIN EC_ORDERS AS B
        ON A.MEMBER_CODE = B.MEMBER_CODE
    WHERE DATE(ORDER_DATETIME) BETWEEN "2023-07-01" AND "2023-07-31"
    GROUP BY A.MEMBER_CODE
),
MEMBERS_LAST_ORDER AS (
    SELECT A.MEMBER_CODE AS CODE, MAX(ORDER_DATETIME) AS ORDER_DATETIME
    FROM MEMBER_MST AS A INNER JOIN EC_ORDERS AS B
        ON A.MEMBER_CODE = B.MEMBER_CODE
    WHERE DATE(ORDER_DATETIME) < "2023-07-01"
    GROUP BY A.MEMBER_CODE
)
SELECT A.ORDER_DATETIME AS ORDER_DATE, A.CODE AS CODE,
    CASE
        WHEN OPTOUT_TYPE = "0" THEN "可"
        WHEN OPTOUT_TYPE = "1" THEN "不可"
        ELSE "不明"
    END AS OPTOUT
FROM MEMBER_MST AS M INNER JOIN MEMBERS_2023_JULY_ORDER AS A
        ON M.MEMBER_CODE = A.CODE
    INNER JOIN MEMBERS_LAST_ORDER AS B
        ON A.CODE = B.CODE
WHERE DATE(B.ORDER_DATETIME) < DATE(A.ORDER_DATETIME, "-1 YEAR")
ORDER BY A.ORDER_DATETIME DESC, A.CODE DESC
提出情報
提出日時2023/10/15 09:34:39
コンテスト第9回 SQLコンテスト
問題クーポン配布対象
受験者Haar
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量78 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
78 MB
データパターン2
AC
78 MB