Hi all!
I'm trying to sum up values from several columns, that way:
id | val1 | val2 | val3 | type1 | type2 | type3 |
val* are double columns, type* are integer columns.
I'd like to select the sum of all val_i columns where the value of the type_i column = 4, so for this expample row
id | val1 | val2 | val3 | type1 | type2 | type3
-----------------------------------------------
1 | 0.1 | 0.2 | 0.3 | 1 | 4 | 4
the resulting sum of val* columns would be 0.5, and the result set would be
id | sum
--------
1 | 0.5
I know this is a table structure problem (I didnt design the table), and please consider that I'm using Firebird and therefore do not have a function like IF().
Any clue how I could select this?
Thanks a lot,
Anne
I'm trying to sum up values from several columns, that way:
id | val1 | val2 | val3 | type1 | type2 | type3 |
val* are double columns, type* are integer columns.
I'd like to select the sum of all val_i columns where the value of the type_i column = 4, so for this expample row
id | val1 | val2 | val3 | type1 | type2 | type3
-----------------------------------------------
1 | 0.1 | 0.2 | 0.3 | 1 | 4 | 4
the resulting sum of val* columns would be 0.5, and the result set would be
id | sum
--------
1 | 0.5
I know this is a table structure problem (I didnt design the table), and please consider that I'm using Firebird and therefore do not have a function like IF().
Any clue how I could select this?
Thanks a lot,
Anne