Subject RE: [firebird-support] SQL - How to ?
Author Thomas Steinmaurer
> Those are:
>
> Type,Number,Amount
> 0,1200,1111
> 0,1200,2222
> 0,1300,3333
> 0,1300,4444
> 1,1500,5555
> 1,1500,6666
> 1,1600,7777
> 2,1200,8888
> 3,1300,9999
>
> I would like to select those records, but those of type 0 and same
> number should be a SUM(Amount).
> The rest - just as they are.
>
> Result should be
>
> 0,1200,3333
> 0,1300,7777
> 1,1500,5555
> 1,1500,6666
> 1,1600,7777
> 3,1200,8888
> 3,1300,9999
>
> Maybe Am just tired but I can't seem to write the prober SQL.....

select
type1
, number
, cast(sum(amount) as integer)
from
test1
where
type1 = 0
group by
type1
, number
union
select
type1
, number
, amount
from
test1
where
type1 > 0

Btw, don't use TYPE as column name. It's a reserved word
in Firebird.


Best Regards,
Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database and MS SQL Server
Upscene Productions
http://www.upscene.com