select countryName, province from stats group by 1,2
select country_name, province from stats group by 1,2
)
, dat as(
select pr.countryName, pr.province, d.today, COALESCE(st.confirmed_count, max(st.confirmed_count) over(partition by pr.province order by d.today)) confirmed_count
select pr.country_name, pr.province, d.today, COALESCE(st.confirmed_count, max(st.confirmed_count) over(partition by pr.province order by d.today)) confirmed_count
from pr
cross join days d
left join stats st on st.province = pr.province and st.today = d.today
order by 1,2,3
)
, rpt as (
select countryName, province, today, confirmed_count, confirmed_count - COALESCE(lag(confirmed_count) over(partition by countryName, province order by today), 0) increase
select country_name, province, today, confirmed_count, confirmed_count - COALESCE(lag(confirmed_count) over(partition by country_name, province order by today), 0) increase
select countryName, province, max(confirmed_count) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_count order by today) confirmed_counts,
select country_name, province, max(confirmed_count) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_count order by today) confirmed_counts,
jsonb_agg(increase order by today) increase,
max(confirmed_sum) confirmed_sum
from ( select *, sum(confirmed_count) over(partition by countryName, today) confirmed_sum from rpt
from ( select *, sum(confirmed_count) over(partition by country_name, today) confirmed_sum from rpt
where province ~ :province
) t
group by 1,2
union all
select countryName, '全国' province, max(confirmed_sum) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_sum order by today) confirmed_counts,
select country_name, '全国' province, max(confirmed_sum) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_sum order by today) confirmed_counts,