23. 유량(Flow)와 저량(Stock)

2024-12-24

select
strftime('%Y', acquisition_date) as "Acquisition year"
, count(*) as "New acquisitions this year (Flow)"
, sum(count(*))over(order by "Acquisition year" rows between unbounded preceding and current row) as "Total collection size (Stock)"
from artworks
where acquisition_date is not null
group by "Acquisition year"
order by acquisition_date

누적 값만 잘 구하면 되는 문제! ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW