Subject RE: [firebird-support] how to build a sum query
Author Sasha Matijasic
> a query should sum the 'value' column , but test the value of the
> 'col_test'
> column : for the 'y' value put the sum in a field , for the 'x' in
> another field :
>
> result should be :
>
> Part | sum_y_values | sum_x_values
> aa 9 6
> cc 17 9
>
> thanks
>
> Mauro
>
>

Hi, something like this maybe, it's not the best solution but it should give you an idea to build it further...

select part, sum(sum_x) sum_x, sum(sum_y) sum_y
from (
select
part,
case when col_test = 'x' then sum(val) else 0 end sum_x,
case when col_test = 'y' then sum(val) else 0 end sum_y
from atable
group by part, col_test
)
group by part

Sasha