ソースコード
WITH A AS (
    SELECT
        CUST_CODE
    FROM (
        SELECT 
            CUST_CODE,
            COUNT(CUST_CODE) AS COUNT
        FROM
            ORDERS
        WHERE
            ORDER_DATE BETWEEN '2023-09-01' AND '2023-09-30'
        GROUP BY
            CUST_CODE
    )
    WHERE
        COUNT >= 5
)
SELECT
    ORDERS.CUST_CODE AS CODE,
    CUSTOMER.CUST_NAME AS NAME,
    COUNT(*) AS CNT,
    SUM(ORDERS.ORDER_AMNT) AS TTL_AMT,
    ROUND(CAST(SUM(ORDERS.ORDER_AMNT) AS float) / COUNT(*), 0) AS AVG_AMT
FROM
    ORDERS
JOIN
    A ON A.CUST_CODE = ORDERS.CUST_CODE
JOIN
    CUSTOMER ON CUSTOMER.CUST_CODE = ORDERS.CUST_CODE
WHERE
    ORDER_DATE BETWEEN '2023-09-01' AND '2023-09-30'
GROUP BY
    ORDERS.CUST_CODE
ORDER BY
    CNT DESC,
    AVG_AMT DESC,
    CODE
;
提出情報
提出日時2023/12/18 09:26:17
コンテスト第10回 SQLコンテスト
問題優良顧客
受験者sepia
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量88 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
88 MB
データパターン2
WA
87 MB