lintry

连续日期中缺失的日期为上一天数据

......@@ -33,15 +33,25 @@ module.exports = function (dbo) {
// 代码逻辑区域
let result = await dbo.query(`
with days as (
select generate_series('2020-01-24'::date, CURRENT_DATE, '1 days')::date today
select generate_series('2020-01-24'::date, CURRENT_DATE, '1 days')::date today
)
select province_short_name, d.today, max(confirmed_count) confirmed_count
, stats as (
select province_short_name province, d.today, max(confirmed_count) confirmed_count
from days d
left join tb_mf_timeline_area ta on ta.update_time::date = d.today
where 1=1
and province_name ~ :province_name
group by 1,2
order by 2, 1
)
, pr as (
select province from stats group by 1
)
select pr.province, d.today, COALESCE(st.confirmed_count, lag(st.confirmed_count) over(partition by pr.province order by d.today))
from pr
cross join days d
left join stats st on st.province = pr.province and st.today = d.today
order by 1,2
`, {replacements: {province_name}, type: dbo.QueryTypes.SELECT});
return Result.Ok('成功!', result);
......@@ -66,11 +76,11 @@ module.exports = function (dbo) {
// 代码逻辑区域
let result = await dbo.query(`
with t as (
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
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
from tb_mf_timeline_area
where update_time::date = :date
)
select update_time, province_short_name, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, country
select update_time, province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, country
from t
where rn = 1
order by confirmed_count desc
......