dbTalk Databases Forums  

SQL problems

comp.database.oracle comp.database.oracle


Discuss SQL problems in the comp.database.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
voodoo
 
Posts: n/a

Default SQL problems - 02-26-2006 , 04:42 PM






I have a this SQL Statement

select DECODE ((SELECT MI.IND

from MAMA MI

where MI.MBD =147193

and MI.IND=182 and

TRUNC(SYSDATE) between MI.FROM_DATE and MI.TO_DATE and

ROWNUM<2 order by mi.CREATED_DATE asc

),'Y','CRIMINAL','N','NOT CRIMINAL' ) PEOPLE from DUAL





Anytime i take the "order by mi.CREATED_DATE asc" out. It executes well
(But it does not serve my purpose). What i am trying to do is i have a table
like

IND MBD CREATED_DATE

Y 147193 02/05/2006

N 147193 02/06/2006

N 147194

Y 147194



I am trying to get the IND status of a person based on the most recent
"created Date". The decodes executes and returns CrminaNot Criminal





Reply With Quote
  #2  
Old   
bdj
 
Posts: n/a

Default Re: SQL problems - 03-10-2006 , 02:32 PM






Hi!
As you see: take care about rownum, sometimes you don't get what you might
expect to get.
Use analytic functions instead.
/Bjoern

"voodoo" <oyesiji (AT) hotmail (DOT) com> skrev i en meddelelse
news:R9qMf.1939$DT.370 (AT) trnddc06 (DOT) ..
Quote:
I have a this SQL Statement

select DECODE ((SELECT MI.IND

from MAMA MI

where MI.MBD =147193

and MI.IND=182 and

TRUNC(SYSDATE) between MI.FROM_DATE and MI.TO_DATE and

ROWNUM<2 order by mi.CREATED_DATE asc

),'Y','CRIMINAL','N','NOT CRIMINAL' ) PEOPLE from DUAL





Anytime i take the "order by mi.CREATED_DATE asc" out. It executes well
(But it does not serve my purpose). What i am trying to do is i have a
table like

IND MBD CREATED_DATE

Y 147193 02/05/2006

N 147193 02/06/2006

N 147194

Y 147194



I am trying to get the IND status of a person based on the most recent
"created Date". The decodes executes and returns CrminaNot Criminal







Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.