lintry

调整字段名

......@@ -37,55 +37,55 @@ module.exports = function (dbo) {
)
, ta as (
select * from (
select countryName, province_short_name province, update_time::date, confirmed_count,
row_number() over(partition by countryName, province_short_name, update_time::date order by update_time desc) rn
select country_name, province_short_name province, update_time::date, confirmed_count,
row_number() over(partition by country_name, province_short_name, update_time::date order by update_time desc) rn
from tb_mf_timeline_area
) t
where rn = 1
)
, stats as (
select countryName, ta.province, d.today, confirmed_count
select country_name, ta.province, d.today, confirmed_count
from days d
left join ta on ta.update_time = d.today
where countryName notnull
where country_name notnull
order by 1,2,3
)
, pr as (
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
from dat
order by 1,2,3
)
, summ as (
select countryName, today, sum(confirmed_count) confirmed_sum, sum(increase) increase
select country_name, today, sum(confirmed_count) confirmed_sum, sum(increase) increase
from rpt
group by 1,2
order by countryName, confirmed_sum desc
order by country_name, confirmed_sum desc
)
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,
jsonb_agg(increase order by today) increase,
max(confirmed_sum)
from summ
where countryName = '中国'
where country_name = '中国'
group by 1
order by countryName, max_count desc
order by country_name, max_count desc
`, {replacements: {province}, type: dbo.QueryTypes.SELECT});
return Result.Ok('成功!', result);
......@@ -111,12 +111,12 @@ module.exports = function (dbo) {
// 代码逻辑区域
let result = await dbo.query(`
with t as (
select update_time, province_short_name province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, countryName, 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_name, row_number() over(partition by province_short_name order by update_time desc) rn
from tb_mf_timeline_area
where update_time::date = :date
and province_name ~ :province
)
select update_time, province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, countryName
select update_time, province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, country_name
from t
where rn = 1
order by confirmed_count desc
......