#serie mensual P,EVP 1980-2019 \copy (with p as (select extract(year from timestart) y,extract(month from timestart) m, extract(day from max(timestart::date)) as day,sum(valor) x, count(valor) n from pmad_cpc where area_id=138 group by y,m order by y,m), evp as (select extract(year from timestart) y,extract(month from timestart) m,sum(valor) x from etpd_wm where area_id=138 group by y,m order by y,m), ev as (select m,avg(x) x from evp group by m) select concat_ws('-',p.y,p.m,p.day) tiempo,p.x,round(ev.x::numeric,2) evp,p.n n_datos_p from p,ev where ev.m=p.m order by p.y,p.m) to p_ev_mensual_s1979_e2019_a138.csv with csv header; #regimen intra-anual 1979-2019 \copy (with p as (select extract(year from timestart) y,extract(month from timestart) m, extract(day from max(timestart::date)) as day,sum(valor) x, count(valor) n from pmad_cpc where area_id=138 group by y,m order by y,m), evp as (select extract(year from timestart) y,extract(month from timestart) m,sum(valor) x from etpd_wm where area_id=138 group by y,m order by y,m), ev as (select m,avg(x) x from evp group by m), query as (select concat_ws('-',p.y,p.m,p.day) tiempo,p.x p,round(ev.x::numeric,2) evp,p.n n_datos_p from p,ev where ev.m=p.m order by p.y,p.m) select extract(month from tiempo) mes,round(avg(p)::numeric,2),round(avg(evp)::numeric,2) evp from query where n_datos_p>=26 group by mes order by mes) to p_ev_avg_s1979_e2019_a138.csv with csv header