Totalize columns in single row with Postgresql

1

I do not understand why it is so difficult to find Documentation and advice to total or add columns in a single row with Postgresql, as it is done in excel:

  

I have tried with CUBE, ROLLUP and CROSSTAB, but I can not finish it.   I appreciate if someone can help me. thanks.

    
asked by Jsierra2017 05.04.2018 в 18:52
source

1 answer

2

I do not know if it's exactly what you want, but you can add a trigger that fills the total per row after each insert and execute something like the following:

select * from table
union 
select 'total' as nombre, sum(2005-1),sum(2005-2),... from table

Now if the detail of the years is in another table, it would get a little more complicated.

    
answered by 05.04.2018 в 19:07