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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Challenging SQL Query Problem. Can you solve it?

Re: Challenging SQL Query Problem. Can you solve it?

From: Karen Hill <karen_hill22_at_yahoo.com>
Date: 22 Dec 2005 14:12:28 -0800
Message-ID: <1135289548.316845.127020@o13g2000cwo.googlegroups.com>

Andy Hassall wrote:
> On 22 Dec 2005 13:45:39 -0800, "Karen Hill" <karen_hill22_at_yahoo.com> wrote:
>
> >T3 wrote:
> >> After looking at both your queries I think it's best if you just
> >> combine them into one that sums both sold and lost for each
> >> salesperson. I think this will work for you.
> >>
> >> SELECT leads.salesman AS Salesperson,
> >> COUNT(DECODE(LOST,-1,1,0)) AS [Number of Lost],
> [snip]
> >
> >Thank you for your response. Is there any way to do it without the
> >DECODE? My DBMS doesn't have DECODE unfortunately.
>
> The more portable replacement for Oracle's DECODE is the CASE statement.
>
> DECODE(x, 1, 'a', 2, 'b', 'c')
>
> =>
>
> CASE
> WHEN x = 1 THEN 'a'
> WHEN x = 2 THEN 'b'
> ELSE 'c'
> END
>
> or
>
> CASE x
> WHEN 1 THEN 'a'
> WHEN 2 THEN 'b'
> ELSE 'c'
> END
Interesting. How would I restate the DECODE into case in T3's example? Bear with me, my head is getting dizzy. Aggregates generally give me the most trouble, and now I can see where Oracle Admins get their reputation for being the best in the world. I would never have thought of using CASE. Could you give a mere mortal a bit more help in how to use CASE to replace decode? Any help would be apprieciated! Received on Thu Dec 22 2005 - 16:12:28 CST

Original text of this message

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