Re: SQL Question - Select if Present ELSE null

Re: SQL Question - Select if Present ELSE null

 

  


SQL> select a.tname, a.date1, a.size1, b.date1, b.size1
2 from test_kg4 a, test_kg4 b where a.tname = b.tname (+)
3 and a.date1='01-JAN-2003' and b.date1(+)='10-JAN-2003';

TNAME DATE1 SIZE1 DATE1 SIZE1
---------- --------- ---------- --------- ----------
T1 01-JAN-03 100 10-JAN-03 200
T2 01-JAN-03 300
T3 01-JAN-03 500 10-JAN-03 600

HTH, Krishna


layzee DBA wrote:
> Hi DBAs
>
> I need some solution to this problem which i am
> facing.
> The requirement is
> SQL>create table test_kg4
> 2 (tname varchar2(10)
> 3 ,date1 date
> 4 ,size1 number
> 5 )
> 6 /
>
> Table created.
>
> SQL>begin
> 2 insert into test_kg4 values('T1','01-Jan-2003',
> 100);
> 3 insert into test_kg4 values('T1','10-Jan-2003',
> 200);
> 4 --
> 5 insert into test_kg4 values('T2','01-Jan-2003',
> 300);
> 6 insert into test_kg4 values('T2','12-Jan-2003',
> 400);
> 7 --
> 8 insert into test_kg4 values('T3','01-Jan-2003',
> 500);
> 9 insert into test_kg4 values('T3','10-Jan-2003',
> 600);
> 10 end;
> 11 /
>
> PL/SQL procedure successfully completed.
>
> SQL>set linesize 100;
> SQL>select * from test_kg4
> 2 /
>
> TNAME DATE1 SIZE1
> ---------- ------------------ ------------
> T1 01-jan-2003:000000 100
> T1 10-jan-2003:000000 200
> T2 01-jan-2003:000000 300
> T2 12-jan-2003:000000 400
> T3 01-jan-2003:000000 500
> T3 10-jan-2003:000000 600
>
> 6 rows selected.
>
> Now if i pass 01-jan-2003 and 10-jan-2003 as parameter
> the output
> should appear as
>
> T1 01-jan-2003 100 10-jan-2003 200
> T2 01-jan-2003 300 -NA- -NA-
> T3 01-jan-2003 500 10-jan-2003 600
>
> Any help would be appreciated.
>
>
>
> =====
> LayZee DBA
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
>
> --------
> Oracle documentation is here: http://tahiti.oracle.com/pls/tahiti/tahiti.homepage
> To unsubscribe: send a blank email to oracledba-[Email Address Removed] To subscribe: send a blank email to oracledba-[Email Address Removed] Visit the list archive: http://www.LAZYDBA.com/odbareadmail.pl
> Tell yer mates about http://www.farAwayJobs.com
> By using this list you agree to these terms:http://www.lazydba.com/legal.html
>
>

Oracle LazyDBA home page