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

Home -> Community -> Usenet -> c.d.o.server -> Re: DECODE

Re: DECODE

From: <joe_celko_at_my-deja.com>
Date: Fri, 11 Feb 2000 15:49:47 GMT
Message-ID: <881b2p$cg6$1@nnrp1.deja.com>

>> SELECT DECODE (deptno,10, 'ACCOUNTING',

                                 20,     'RESEARCH',
                                 30,     'OPERATION',
                                 40,     'OPERATION',
                                         'NONE')
 COUNT(*)
  FROM TableA
 GROUP BY deptno;

is there anyway for me to group by the decoded values rather than the original stored values ? <<

If I understnad what you want, try this:

SELECT  SUM(DECODE (deptno, 10, 1, 0))AS Accounting,
        SUM(DECODE (deptno, 20, 1, 0)) AS Research,
        SUM(DECODE (deptno, 30, 1, 40, 1, 0) AS Operations,
        (COUNT(*) - (Accounting + Research + Operations)) AS none
 FROM TableA;

--CELKO-- Sent via Deja.com http://www.deja.com/
Before you buy. Received on Fri Feb 11 2000 - 09:49:47 CST

Original text of this message

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