ソースコード
WITH abc as (SELECT
    CAST(STRFTIME('%w', SALES_DATE) AS INTEGER) AS DAY_OF_WEEK,
    CASE CAST(STRFTIME('%w', SALES_DATE) AS INTEGER)
        WHEN 0 THEN '日'
        WHEN 1 THEN '月'
        WHEN 2 THEN '火'
        WHEN 3 THEN '水'
        WHEN 4 THEN '木'
        WHEN 5 THEN '金'
        ELSE '土'
    END AS WEEK,
    IFNULL(ROUND(SUM(CASE WHEN SALES_TYPE <> 2 AND UPDATED_NO IS NULL THEN 1 ELSE 0 END) / 4.0, 0), 0) AS AVG_CNT,
    IFNULL(
            case
            when cast(ROUND(SUM(CASE WHEN SALES_TYPE <> 2 AND UPDATED_NO IS NULL THEN SALES_AMT ELSE 0 END) / 4.0, 0) as int) <1000 then
                cast(ROUND(SUM(CASE WHEN SALES_TYPE <> 2 AND UPDATED_NO IS NULL THEN SALES_AMT ELSE 0 END) / 4.0, 0) as int)
            when cast(ROUND(SUM(CASE WHEN SALES_TYPE <> 2 AND UPDATED_NO IS NULL THEN SALES_AMT ELSE 0 END) / 4.0, 0) as int) < 1000000 then
                cast(ROUND(SUM(CASE WHEN SALES_TYPE <> 2 AND UPDATED_NO IS NULL THEN SALES_AMT ELSE 0 END) / 4.0 , 0)/1000 as int) || ','|| cast(ROUND(SUM(CASE WHEN SALES_TYPE <> 2 AND UPDATED_NO IS NULL THEN SALES_AMT ELSE 0 END) / 4.0, 0)%1000 as int)
            when cast(ROUND(SUM(CASE WHEN SALES_TYPE <> 2 AND UPDATED_NO IS NULL THEN SALES_AMT ELSE 0 END) / 4.0, 0) as int) < 1000000000 then
                cast(ROUND(SUM(CASE WHEN SALES_TYPE <> 2 AND UPDATED_NO IS NULL THEN SALES_AMT ELSE 0 END) / 4.0 , 0)/1000000 as int)
                || ','||
                cast(ROUND(SUM(CASE WHEN SALES_TYPE <> 2 AND UPDATED_NO IS NULL THEN SALES_AMT ELSE 0 END) / 4.0 , 0)/1000 %1000 as int)
                || ','||
                cast(ROUND(SUM(CASE WHEN SALES_TYPE <> 2 AND UPDATED_NO IS NULL THEN SALES_AMT ELSE 0 END) / 4.0, 0)%1000 as int)
            END
            || '円'
        , '0円'
        ) AS AVG_AMT
FROM
    SALES
GROUP BY
    DAY_OF_WEEK
ORDER BY
    DAY_OF_WEEK
)
SELECT WEEK,AVG_CNT,AVG_AMT FROM abc;
提出情報
提出日時2024/04/20 09:16:00
コンテスト第12回 SQLコンテスト
問題曜日別売上分析
受験者swamp
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
WA
86 MB