ソースコード
WITH
    SALES_SUM AS (
        SELECT
            STRFTIME ('%w', SALES_DATE) AS WEEK_NO,
            SUBSTR ('日月火水木金土', STRFTIME ('%w', SALES_DATE) + 1, 1) AS WEEK_NAME,
            ROUND(CAST(COUNT(SALES_NO) AS REAL) / 4.0) AS AVG_CNT,
            CAST(ROUND(CAST(SUM(SALES_AMT) AS REAL) / 4.0) AS INT) AS AVG_SA_AMT
        FROM
            SALES
        WHERE
            SALES_DATE BETWEEN '2024-03-01' AND '2024-03-28'
            AND SALES_TYPE <> 2
            AND UPDATED_NO IS NULL
        GROUP BY
            WEEK_NO
    ),
    WEEK_TBL AS (
        SELECT
            '2024-03-01' AS CLDATE,
            STRFTIME ('%w', '2024-03-01') AS WEEK_NO,
            SUBSTR ('日月火水木金土', STRFTIME ('%w', '2024-03-01') + 1, 1) AS WEEK_NAME
        UNION ALL
        SELECT
            DATE(CLDATE, '+1 days'),
            STRFTIME ('%w', DATE(CLDATE, '+1 days')),
            SUBSTR (
                '日月火水木金土',
                STRFTIME ('%w', DATE(CLDATE, '+1 days')) + 1,
                1
            )
        FROM
            WEEK_TBL
        WHERE
            CLDATE < '2024-03-07'
    )
SELECT
    wt.WEEK_NAME AS WEEK,
    COALESCE(ss.AVG_CNT, 0) AS AVG_CNT,
    printf ('%,d円', ifnull (ss.AVG_SA_AMT, 0)) as AVG_AMT
FROM
    WEEK_TBL AS wt
    LEFT OUTER JOIN SALES_SUM AS ss ON ss.WEEK_NO = wt.WEEK_NO
ORDER BY
    wt.WEEK_NO ASC;
提出情報
提出日時2024/06/29 12:11:49
コンテスト第12回 SQLコンテスト
問題曜日別売上分析
受験者kwm_t
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
85 MB