Subject | Re: [firebird-support] Simple sql query question |
---|---|
Author | Martijn Tonies |
Post date | 2004-11-05T11:04:30Z |
Hello,
select Field1, Sum(Field2)
from yourtable
group by Field1
With regards,
Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com
> I am wondering is it possible to get this result without writting UDF.This result isn't possible with an UDF :-)
> There is a table:You cannot get this in 1 row, but you can get the right results:
> 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 Field1, Sum(Field2)
from yourtable
group by Field1
With regards,
Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com