Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Analyzing This Query?
Greetings,
I have a query
SELECT
DECODE(SODC.CONTRASEQNUMBER, 1, SODC.CONTRAQUANTITY,0) CQTY1,
DECODE(SODC.CONTRASEQNUMBER, 2, SODC.CONTRAQUANTITY,0) CQTY2,
DECODE(SODC.CONTRASEQNUMBER, 3, SODC.CONTRAQUANTITY,0) CQTY3,
DECODE(SODC.CONTRASEQNUMBER, 4, SODC.CONTRAQUANTITY,0) CQTY4,
DECODE(SODC.CONTRASEQNUMBER, 5, SODC.CONTRAQUANTITY,0) CQTY5,
DECODE(SODC.CONTRASEQNUMBER, 1, SODC.CONTRANAME,0) CONTRA1,
DECODE(SODC.CONTRASEQNUMBER, 2, SODC.CONTRANAME,0) CONTRA2,
DECODE(SODC.CONTRASEQNUMBER, 3, SODC.CONTRANAME,0) CONTRA3,
DECODE(SODC.CONTRASEQNUMBER, 4, SODC.CONTRANAME,0) CONTRA4,
DECODE(SODC.CONTRASEQNUMBER, 5, SODC.CONTRANAME,0) CONTRA5,
FROM
SEMCOMPANIES SODC
As we can see that the CONTRASEQNUMBER is checked first from the value
1 to 5 to give the output as CQTY1, CQTY2 etc
and then again is checked from 1 through 5 to give the result as
CONTRA1, CONTRA2, etc
i.e according to the flow, CONTRASEQNUMBER is checked twice for the
same values
I just wanted to know is there any way these two results can be
obtained
where the CONTRASEQNUMBER is checked only once from 1 to 5 or is there
any other recommended approach to follow?
We are using Oracle 10g.
Any help would be greatly appreciated
TIA Received on Mon Feb 13 2006 - 00:40:08 CST