ソースコード
with WEEK_TBL as(
select '0' as WEEK_NO, '日' as WEEK
union select '1' as WEEK_NO, '月' as WEEK
union select '2' as WEEK_NO, '火' as WEEK
union select '3' as WEEK_NO, '水' as WEEK
union select '4' as WEEK_NO, '木' as WEEK
union select '5' as WEEK_NO, '金' as WEEK
union select '6' as WEEK_NO, '土' as WEEK
)

select
    W.WEEK
    ,ifnull(round(avg(DAILY_CNT),0),0) as AVG_CNT
    ,case 
    when length(cast(round(avg(DAILY_AVG),0) as string))>8 then
    substr(cast(round(avg(DAILY_AVG),0) as string),1,length(cast(round(avg(DAILY_AVG),0) as string))-8) || ','
    || substr(cast(round(avg(DAILY_AVG),0) as string),length(cast(round(avg(DAILY_AVG),0) as string))-7,3) || ','
    || substr(cast(round(avg(DAILY_AVG),0) as string),length(cast(round(avg(DAILY_AVG),0) as string))-4,3) || '円'
    when length(cast(round(avg(DAILY_AVG),0) as string))>5 then
    substr(cast(round(avg(DAILY_AVG),0) as string),1,length(cast(round(avg(DAILY_AVG),0) as string))-5) || ','
    || substr(cast(round(avg(DAILY_AVG),0) as string),length(cast(round(avg(DAILY_AVG),0) as string))-4,3) || '円'
    when length(cast(round(avg(DAILY_AVG),0) as string))>2 then
    substr(cast(round(avg(DAILY_AVG),0) as string),1,length(cast(round(avg(DAILY_AVG),0) as string))-2) || '円' 
    else '0円'
    end as AVG_AMT
from (
    select
        strftime('%w',SALES_DATE) as WEEK_NO
        ,count(*) as DAILY_CNT
        ,avg(SALES_AMT) as DAILY_AVG
    from
        SALES
    where
        SALES_DATE between '2024-03-01' and '2024-03-28'
        and SALES_TYPE<>2
        and UPDATED_NO is null
    group by
        SALES_DATE
    ) as SUB
    right outer join
    WEEK_TBL as W
    on W.WEEK_NO=SUB.WEEK_NO
group by
    SUB.WEEK_NO
提出情報
提出日時2024/04/22 10:17:56
コンテスト第12回 SQLコンテスト
問題曜日別売上分析
受験者honyara
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
86 MB
データパターン2
WA
83 MB