Showing
1 changed file
with
13 additions
and
3 deletions
| ... | @@ -35,13 +35,23 @@ module.exports = function (dbo) { | ... | @@ -35,13 +35,23 @@ module.exports = function (dbo) { |
| 35 | with days as ( | 35 | with days as ( |
| 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 | - select province_short_name, d.today, max(confirmed_count) confirmed_count | 38 | + , stats as ( |
| 39 | + select province_short_name province, d.today, max(confirmed_count) confirmed_count | ||
| 39 | from days d | 40 | from days d |
| 40 | left join tb_mf_timeline_area ta on ta.update_time::date = d.today | 41 | left join tb_mf_timeline_area ta on ta.update_time::date = d.today |
| 41 | where 1=1 | 42 | where 1=1 |
| 42 | and province_name ~ :province_name | 43 | and province_name ~ :province_name |
| 43 | group by 1,2 | 44 | group by 1,2 |
| 44 | order by 2, 1 | 45 | order by 2, 1 |
| 46 | + ) | ||
| 47 | + , pr as ( | ||
| 48 | + select province from stats group by 1 | ||
| 49 | + ) | ||
| 50 | + select pr.province, d.today, COALESCE(st.confirmed_count, lag(st.confirmed_count) over(partition by pr.province order by d.today)) | ||
| 51 | + from pr | ||
| 52 | + cross join days d | ||
| 53 | + left join stats st on st.province = pr.province and st.today = d.today | ||
| 54 | + order by 1,2 | ||
| 45 | `, {replacements: {province_name}, type: dbo.QueryTypes.SELECT}); | 55 | `, {replacements: {province_name}, type: dbo.QueryTypes.SELECT}); |
| 46 | 56 | ||
| 47 | return Result.Ok('成功!', result); | 57 | return Result.Ok('成功!', result); |
| ... | @@ -66,11 +76,11 @@ module.exports = function (dbo) { | ... | @@ -66,11 +76,11 @@ module.exports = function (dbo) { |
| 66 | // 代码逻辑区域 | 76 | // 代码逻辑区域 |
| 67 | let result = await dbo.query(` | 77 | let result = await dbo.query(` |
| 68 | with t as ( | 78 | with t as ( |
| 69 | - select update_time, province_short_name, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, country, row_number() over(partition by province_short_name order by update_time desc) rn | 79 | + select update_time, province_short_name province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, country, row_number() over(partition by province_short_name order by update_time desc) rn |
| 70 | from tb_mf_timeline_area | 80 | from tb_mf_timeline_area |
| 71 | where update_time::date = :date | 81 | where update_time::date = :date |
| 72 | ) | 82 | ) |
| 73 | - select update_time, province_short_name, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, country | 83 | + select update_time, province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, country |
| 74 | from t | 84 | from t |
| 75 | where rn = 1 | 85 | where rn = 1 |
| 76 | order by confirmed_count desc | 86 | order by confirmed_count desc | ... | ... |
-
Please register or login to post a comment