lintry

调整排序

...@@ -36,16 +36,19 @@ module.exports = function (dbo) { ...@@ -36,16 +36,19 @@ module.exports = function (dbo) {
36 select generate_series('2020-01-24'::date, CURRENT_DATE, '1 days')::date today 36 select generate_series('2020-01-24'::date, CURRENT_DATE, '1 days')::date today
37 ) 37 )
38 , ta as ( 38 , ta as (
39 - 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 39 + select * from (
40 + select country, province_short_name province, update_time::date, confirmed_count,
41 + row_number() over(partition by country, province_short_name, update_time::date order by update_time desc) rn
40 from tb_mf_timeline_area 42 from tb_mf_timeline_area
43 + ) t
44 + where rn = 1
41 ) 45 )
42 , stats as ( 46 , stats as (
43 - select country, ta.province, d.today, max(confirmed_count) confirmed_count 47 + select country, ta.province, d.today, confirmed_count
44 from days d 48 from days d
45 - left join ta on ta.update_time::date = d.today and ta.rn = 1 49 + left join ta on ta.update_time = d.today
46 - where 1=1 50 + where country notnull
47 and province ~ :province 51 and province ~ :province
48 - group by 1,2,3
49 order by 1,2,3 52 order by 1,2,3
50 ) 53 )
51 , pr as ( 54 , pr as (
...@@ -61,6 +64,7 @@ module.exports = function (dbo) { ...@@ -61,6 +64,7 @@ module.exports = function (dbo) {
61 , rpt as ( 64 , rpt as (
62 select country, province, today, confirmed_count, confirmed_count - COALESCE(lag(confirmed_count) over(partition by country, province order by today), 0) increase 65 select country, province, today, confirmed_count, confirmed_count - COALESCE(lag(confirmed_count) over(partition by country, province order by today), 0) increase
63 from dat 66 from dat
67 + order by 1,2,3
64 ) 68 )
65 , summ as ( 69 , summ as (
66 select country, today, sum(confirmed_count) confirmed_sum, sum(increase) increase 70 select country, today, sum(confirmed_count) confirmed_sum, sum(increase) increase
...@@ -68,15 +72,15 @@ module.exports = function (dbo) { ...@@ -68,15 +72,15 @@ module.exports = function (dbo) {
68 group by 1,2 72 group by 1,2
69 order by country, confirmed_sum desc 73 order by country, confirmed_sum desc
70 ) 74 )
71 - select country, province, max(confirmed_count) max_count, jsonb_agg(today) days, jsonb_agg(confirmed_count) confirmed_counts, 75 + select country, province, max(confirmed_count) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_count order by today) confirmed_counts,
72 - jsonb_agg(increase) increase, 76 + jsonb_agg(increase order by today) increase,
73 max(confirmed_sum) confirmed_sum 77 max(confirmed_sum) confirmed_sum
74 from ( select *, sum(confirmed_count) over(partition by country, today) confirmed_sum from rpt 78 from ( select *, sum(confirmed_count) over(partition by country, today) confirmed_sum from rpt
75 ) t 79 ) t
76 group by 1,2 80 group by 1,2
77 union all 81 union all
78 - select country, '全国' province, max(confirmed_sum) max_count, jsonb_agg(today) days, jsonb_agg(confirmed_sum) confirmed_counts, 82 + select country, '全国' province, max(confirmed_sum) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_sum order by today) confirmed_counts,
79 - jsonb_agg(increase) increase, 83 + jsonb_agg(increase order by today) increase,
80 max(confirmed_sum) 84 max(confirmed_sum)
81 from summ 85 from summ
82 where country = '中国' 86 where country = '中国'
......