Subject RE: [firebird-support] how to build a sum query
Author Mercea Paul
And better solution is

select part, sum(case t.col_test when 'y' then t.v_value else 0 end) sum_y,
sum(case t.col_test when 'x' then t.v_value else 0 end) sum_x
from testare t
group by 1

Regards,
Paul

> -----Original Message-----
> From: firebird-support@yahoogroups.com [mailto:firebird-
> support@yahoogroups.com] On Behalf Of Maurizio
> Sent: 14 June 2008 09:06
> To: firebird-support@yahoogroups.com
> Subject: [firebird-support] how to build a sum query
>
> hi , i would like to know if possible , and how ,
> to do this :
>
> the table i have :
>
> col_test | value | Part
> y 2 aa
> x 4 cc
> y 10 cc
> y 7 cc
> x 2 aa
> x 4 aa
> x 5 cc
> y 7 aa
>
> 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
>
>
>
> ------------------------------------
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Yahoo! Groups Links
>
>
>