Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: Need Help with SQL - Repost

Re: Need Help with SQL - Repost

From: David Fitzjarrell <oratune_at_aol.com>
Date: Thu, 11 Jan 2001 23:08:02 GMT
Message-ID: <93lecd$14d$1@nnrp1.deja.com>

In our last gripping episode "Anna Henson" <anna_henson_at_yahoo.com> wrote:
> Hello Oracle Users,
>
> I would like to write a query similar to the one below, but Oracle
 does not
> accept 'IF' statement. Is there anyother way to
> write a query similar to the one below.
>
> select a.score , (If b.score in (11,12,13) then InActive=1),
> (If b.score NOT in (11,12,13) then Active=1), sum(b.Balance)
>
> from OldTable a, NewTable b
> group by a.score;
>
> Thanks,
>
> Anna Henson
>
>

Well, now that the query is properly stated:

select a.score, decode(b.score, 11, 1, 12, 1, 13, 1) as InActive,
                decode(b.score, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1,
                                7, 1, 8, 1, 9, 1, 10, 1, 14, 1, 15, 1)
as Active,
       sum(b.balance)

from oldtable a, newtable b
group by a.score, decode(b.score, 11, 1, 12, 1, 13, 1),
         decode(b.score, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1,
                                7, 1, 8, 1, 9, 1, 10, 1, 14, 1, 15, 1);

Again, I have no idea what you will be using this query to determine.

--
David Fitzjarrell
Oracle Certified DBA


Sent via Deja.com
http://www.deja.com/
Received on Thu Jan 11 2001 - 17:08:02 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US