lintry

调整排序

......@@ -36,16 +36,19 @@ module.exports = function (dbo) {
select generate_series('2020-01-24'::date, CURRENT_DATE, '1 days')::date today
)
, ta as (
select country, province_short_name province, update_time, confirmed_count, row_number() over(partition by country, province_short_name order by update_time desc) rn
select * from (
select country, province_short_name province, update_time::date, confirmed_count,
row_number() over(partition by country, province_short_name, update_time::date order by update_time desc) rn
from tb_mf_timeline_area
) t
where rn = 1
)
, stats as (
select country, ta.province, d.today, max(confirmed_count) confirmed_count
select country, ta.province, d.today, confirmed_count
from days d
left join ta on ta.update_time::date = d.today and ta.rn = 1
where 1=1
left join ta on ta.update_time = d.today
where country notnull
and province ~ :province
group by 1,2,3
order by 1,2,3
)
, pr as (
......@@ -61,6 +64,7 @@ module.exports = function (dbo) {
, rpt as (
select country, province, today, confirmed_count, confirmed_count - COALESCE(lag(confirmed_count) over(partition by country, province order by today), 0) increase
from dat
order by 1,2,3
)
, summ as (
select country, today, sum(confirmed_count) confirmed_sum, sum(increase) increase
......@@ -68,15 +72,15 @@ module.exports = function (dbo) {
group by 1,2
order by country, confirmed_sum desc
)
select country, province, max(confirmed_count) max_count, jsonb_agg(today) days, jsonb_agg(confirmed_count) confirmed_counts,
jsonb_agg(increase) increase,
select country, 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 country, today) confirmed_sum from rpt
) t
group by 1,2
union all
select country, '全国' province, max(confirmed_sum) max_count, jsonb_agg(today) days, jsonb_agg(confirmed_sum) confirmed_counts,
jsonb_agg(increase) increase,
select country, '全国' province, max(confirmed_sum) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_sum order by today) confirmed_counts,
jsonb_agg(increase order by today) increase,
max(confirmed_sum)
from summ
where country = '中国'
......