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

Re: Need Help with SQL

From: David Fitzjarrell <oratune_at_aol.com>
Date: Thu, 11 Jan 2001 23:01:32 GMT
Message-ID: <93le06$um$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)) as InActive,
> (If b.score NOT in (11,12,13) as Active, sum(b.Balance)
>
> from OldTable a, NewTable b
> group by a.score;
>
> Thanks,
>
> Anna Henson
>
>

This may work to your satisfaction, although it requires 8.1.6:

select a.score, (case when to_char(b.score) in ('11','12','13') then 'InActive' else 'Active' end), sum(b.balance) from OldTable a, NewTable b
group by a.score, to_char(b.score);

Since you are wanting the sum of a column you will need to group by all remaining non-grouped columns. I cannot make sense of the output from this query, but it does work under 8.1.6.

--
David Fitzjarrell
Oracle Certified DBA


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

Original text of this message

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