I need to calculate several values from a field in a table depending on a code in another field of the same table.
The table is in a PostgreSQL 8.3 database.
Table:
cod_1 | cod_2 | date | cod_sum| import
1 | 2 | 01/01/2012 | a | 1.1
1 | 2 | 01/01/2012 | a | 1.2
1 | 2 | 01/01/2012 | b | 1.1
1 | 2 | 01/01/2012 | b | 1.1
1 | 2 | 01/01/2012 | c | 1.1
1 | 2 | 01/01/2012 | c | 1.1
I need something like this:
cod_1 | cod_2 |date |sum_import_a|sum_import_b|calc_import_abc(a+b-c)
1 | 2 |01/01/2012| 2.3 | 2.2 | 2.3 (2.3+2.2-2.2)
I hope you can lend a hand ...