ソースコード
with weekdays as (
select '0' as WEEK_NO, '日' as WEEK union all
select '1', '月' union all
select '2', '火' union all
select '3', '水' union all
select '4', '木' union all
select '5', '金' union all
select '6', '土'
)
, summary as(select sales.sales_date, strftime('%w', sales_date) as WEEK_NO, count(1) as CNT, sum(sales.sales_amt) as SUM_AMT
from sales
where sales.sales_type != 2 and sales.updated_no is null
group by sales.sales_date
)
, weekday_summary as (select WEEK_NO, ROUND((1.0 * sum(CNT) / 4)) as AVG_CNT, ROUND((1.0 * sum(SUM_AMT) / 4)) as AVG_AMT
from summary
group by WEEK_NO
)
select 
weekdays.WEEK as WEEK,
ifnull(weekday_summary.AVG_CNT, 0) as AVG_CNT,
case
when weekday_summary.AVG_AMT is null then '0'
else printf("%,d", weekday_summary.AVG_AMT)
end || '円' as AVG_AMT
from weekdays left join weekday_summary on weekdays.WEEK_NO = weekday_summary.WEEK_NO
order by weekdays.WEEK_NO
提出情報
提出日時2024/04/25 18:08:33
コンテスト第12回 SQLコンテスト
問題曜日別売上分析
受験者daku10
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
WA
84 MB