ソースコード
with a as(
select 
SALES_DATE dt,
cast((strftime('%w',SALES_DATE)) as integer) wk,
sales_amt
 from sales 
where SALES_DATE between '2024-03-01'  and '2024-03-28' 
and SALES_TYPE <> 2 and 
UPDATED_NO is null
)
,
SEQ AS (SELECT 0 as no UNION ALL SELECT no + 1 as no FROM SEQ WHERE no + 1 < 7)
select
WEEK,
amt as 'AVG_CNT',
(
WITH SEQ AS (SELECT amt2 a, null b,0 as no UNION ALL 
SELECT substr(a,1,length(a)-3), substr(a,-3) b,no+1 FROM SEQ WHERE length(a)>=1)
select group_concat(b)  from (select * from seq order by no desc) where b is not null
) || '円' AS 'AVG_AMT'
from
(
select 
seq.no no,
substr('日月火水木金土日',seq.no+1,1) as WEEK,
ifnull(cast(round(cast(count(a.dt) as real)/4.0,0) as integer),0) amt,
ifnull(cast(round(cast(sum(SALES_AMT) as real)/4.0,0) as integer),0) amt2
 from seq left join a
 on seq.no=a.wk
group by seq.no
)
order by no
提出情報
提出日時2024/04/19 20:33:17
コンテスト第12回 SQLコンテスト
問題曜日別売上分析
受験者tamurakami
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
84 MB