Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: query needed very urg.
peter wrote:
> Hi all,
> Please tell me query for following conditions:
>
> Conditions are:
>
> 1) a=12, b=3, n=7
> 2) a=12, b=3, n=NULL
> 3) a=12, b=NULL, n=NULL
>
> if 1 is true, I don't need any record of 2 or 3. But if it is false
> then
> I need all record of 2, but if 1 and 2 both are wrong then only I need
> 3.
Hi Peter, please find inline code for creating test data and the SQL query you require from my understanding of your post. Note that the example I have created executes on 10.1.0.4 - you omitted the target Oracle version from your post.
Regards
Mike
TESSELLA Michael.OShea_at_tessella.com
__/__/__/ Tessella Support Services plc __/__/__/ 3 Vineyard Chambers, ABINGDON, OX14 3PX, England __/__/__/ Tel: (44)(0)1235-555511 Fax: (44)(0)1235-553301www.tessella.com Registered in England No. 1466429
SQL> SQL> SQL> CREATE TABLE tblTest(a NUMBER, b NUMBER, n NUMBER, whateverElseVARCHAR2(15)); Table created.
SQL> INSERT INTO tblTest(a,b,n,whateverElse ) 2 VALUES(12,3,7,'condition 1');
1 row created.
SQL> INSERT INTO tblTest(a,b,n,whateverElse ) 2 VALUES(12,3,NULL,'condition 2.1');
1 row created.
SQL> INSERT INTO tblTest(a,b,n,whateverElse ) 2 VALUES(12,3,NULL,'condition 2.2');
1 row created.
SQL> INSERT INTO tblTest(a,b,n,whateverElse ) 2 VALUES(12,NULL,NULL,'condition 3');
1 row created.
SQL>
SQL> SELECT a,b,n,whateverElse
2 FROM
3 (
4 SELECT t.*, 5 DENSE_RANK() OVER (PARTITION BY a ORDER BY a,b,n) rn 6 FROM tblTest t 7 WHERE a=12 8 AND NVL(b,3)=3 9 AND NVL(n,7)=7
A B N WHATEVERELSE ---------- ---------- ---------- ---------------
12 3 7 condition 1
SQL> SELECT *
2 FROM V$VERSION;
BANNER
SQL> SQL> SQL>Received on Thu Dec 14 2006 - 03:09:10 CST