Subject Re: [firebird-support] SQL Question
Author Arno Brinkman
Hi,

> I have a table.
> This tables has a record for each month of the year.
>
> I can select some values from this month and display them.
> I can select a SUM of values from a range of months a display them
>
> But is it posible to do both of the above, and have the return values
> on 1 line ?
>
>
> Exampel:
>
> TABEL
> MONTH SOME VALUE
> 1 11
> 2 22
> 3 33
> 4 44
> 5 55
> 6 66
>
> If I select he value from month 6 it'll return 66.
> If I select SUM of values where month is greater than or equal to 1
> it returns 231.
>
> Can I make a SQL that return both 66 and 231 in some way ?

In Firbird 1.5 you can use CASE for this

SELECT
SUM(CASE WHEN t1.Month >= 1 THEN t1.SomeValue ELSE 0 END),
SUM(CASE WHEN t1.Month = 6 THEN t1.SomeValue ELSE 0 END)
FROM
ATable t1

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://newsgroups.firebirdsql.info