Subject Re: [firebird-support] SQL - How to ?
Author Martijn Tonies
Hello Michael,

> I have a table containing 9 records.
>
> 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 type_, number, cast(sum(amount) as int)
from w
where type_ = 0
group by type_, number
union
select type_, number, amount
from w
where type_ <> 0

With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com