Subject RE: [firebird-support] how to build a sum query
Author Mercea Paul
Try this

select part, ( select sum(t2.v_value) from testare t2 where t2.col_test='y'
and t2.part=t.part ) sum_y,
( select sum(t3.v_value) from testare t3 where t3.col_test='x' and
t3.part=t.part ) sum_x
from testare t
group by 1

I have renamed colum value to v_value

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
>
>
>