Subject Re: [firebird-support] Simple sql query question
Author Arno Brinkman
Hi,

> I am wondering is it possible to get this result without writting UDF.
>
> There is a table:
> Field1 Field2
> ---------------
> 1 2
> 1 1
> 1 3
> 2 4
> 2 1
> 2 3
> ---------------
>
> I need to get in one recod sum() of Field2 according to Field1. Wanted
> result:
>
> ResField1 ResField2
> ---------------------
> 6 8
> ---------------------
>
> 6 = 2+1+3 (Field1 = 1)
> 8 = 4+1+3 (Field2 = 2)

SELECT
(SELECT SUM(Field2) FROM TableX WHERE Field1 = 1) AS ResField1,
(SELECT SUM(Field2) FROM TableX WHERE Field1 = 2) AS ResField2
FROM
RDB$DATABASE

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/

Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep :
news://80.126.130.81