Subject | Re: SQL Question |
---|---|
Author | Michael Vilhelmsen |
Post date | 2004-06-03T10:20:35Z |
thank you Arno.
Does this work with FB 1.0 as well ?
Michael
--- In firebird-support@yahoogroups.com, "Arno Brinkman"
<firebird@a...> wrote:
Does this work with FB 1.0 as well ?
Michael
--- In firebird-support@yahoogroups.com, "Arno Brinkman"
<firebird@a...> wrote:
> Hi,values
>
> > 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
> > on 1 line ?1
> >
> >
> > 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
> > it returns 231.features :
> >
> > 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
> 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