ソースコード
SELECT
    SUB.ORDER_DATETIME AS ORDER_DATE,
    SUB.MEMBER_CODE AS CODE,
    CASE M.OPTOUT_TYPE
        WHEN 0 THEN '可'
        WHEN 1 THEN '不可'
        ELSE '不明'
    END AS OPTOUT
FROM
    (
        SELECT
            MEMBER_CODE AS MEMBER_CODE,
            MIN(ORDER_DATETIME) AS ORDER_DATETIME,
            MIN(DATE(ORDER_DATETIME)) AS M_DATE
        FROM
            EC_ORDERS
        WHERE
            DATE(ORDER_DATETIME) BETWEEN '2023-07-01' AND '2023-07-31'
        GROUP BY
            MEMBER_CODE
    ) AS SUB
    INNER JOIN MEMBER_MST AS M ON M.MEMBER_CODE = SUB.MEMBER_CODE
WHERE
    EXISTS (
        SELECT
            ORDER_NO
        FROM
            EC_ORDERS
        WHERE
            SUB.MEMBER_CODE = MEMBER_CODE
            AND DATE(ORDER_DATETIME) < DATE(SUB.M_DATE, '-1 year')
    )
    AND NOT EXISTS (
        SELECT
            ORDER_NO
        FROM
            EC_ORDERS
        WHERE
            SUB.MEMBER_CODE = MEMBER_CODE
            AND DATE(ORDER_DATETIME) BETWEEN DATE(SUB.M_DATE, '-1 year') AND DATE(SUB.M_DATE, '-1 day')
    )
ORDER BY
    ORDER_DATE DESC,
    CODE DESC;
            SUB.MEMBER_CODE = MEMBER_CODE
            AND DATE(ORDER_DATETIME) BETWEEN DATE(SUB.M_DATE, '-1 year') AND DATE(SUB.M_DATE, '-1 day')
    )
ORDER BY
    ORDER_DATE DESC,
    CODE DESC;
提出情報
提出日時2024/06/22 16:50:30
コンテスト第9回 SQLコンテスト
問題クーポン配布対象
受験者kwm_t
状態 (詳細)RE
(Runtime Error: 実行時エラー)
メモリ使用量83 MB
メッセージ
SQLITE_ERROR: near "SUB": syntax error
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
RE
83 MB
データパターン2
RE
83 MB