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: Andy Hassall <andy_at_andyh.co.uk>
Date: Thu, 22 Dec 2005 22:00:16 +0000
Message-ID: <ga8mq156j06buuo4n360hlem4207jj4ots@4ax.com>


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

-- 
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Received on Thu Dec 22 2005 - 16:00:16 CST

Original text of this message

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