Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem Using RANK() OVER ( partition by)

HesipesiNov 5 2013 — edited Nov 5 2013

Hi,

I have a select statement which selects just one record among many records sorted by timestamp!

SELECT     isin,      id ,       mkt ,       ccy,TM

               FROM 

         ( SELECT isin,      id ,       mkt ,       ccy, TM,

         RANK() OVER ( partition by isin order by TM asc ) RNK

         FROM      testt  )

         where  'RUSF'      =    id

         and     'SSEFN'   =   mkt

         AND rnk= 1

By this statement i'll get just one record (rnk= 1 so it select the first record)

But the problem is that whenever there is just one record (meeting the conditions) it doesn't show up in the result set!!

And i'll also need that record! My purpose is to always just one record no matter how many they are!

I have attached one sample record and also the table script here!

SE0001RUSFSSENSSS2013-04-16 06:55:37
SE0005RUSFSSENSSS2013-11-04 06:57:16

CREATE TABLE testt

(

  ISIN       VARCHAR2(13 BYTE)                  NOT NULL,

  ID         VARCHAR2(33 BYTE),

  TM         VARCHAR2(20 BYTE),

  TMMILL     NUMBER(13),

  TMMILLREC  NUMBER(13),

  NM         VARCHAR2(49 BYTE),

  MKT        VARCHAR2(11 BYTE)                  NOT NULL,

  CCY        VARCHAR2(4 BYTE)

)

;

This post has been answered by Frank Kulash on Nov 5 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 3 2013
Added on Nov 5 2013
8 comments
1,536 views