If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > Alternative for rank() operator

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-28-10, 00:25
januincse januincse is offline
Registered User
 
Join Date: Dec 2010
Posts: 1
Alternative for rank() operator

Hi,

I am using rank() over(partition by ) operator to find rank in a query.

But in performance side, partition by is ver slow and query is executing a very long time.

can you please suggest an effective alternative to this partition by?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 01-09-11, 23:38
alirulez999 alirulez999 is offline
Registered User
 
Join Date: Jan 2010
Posts: 25
Let say you need the output like this:

EmpId RNK
101 1
101 2
101 3
102 1
102 2
103 1


step 1:
Polulate and identity column

EmpId Identity
101 1
101 2
101 3
102 4
102 5
103 6


Step 2: take the min of the identity for each of the group of EMpId


EmpId Identity min(identity)
101 1 1
101 2 1
101 3 1
102 4 4
102 5 4
103 6 6


Step 3: Subtract the identity field from min(identity) and add 1


EmpId Identity min(identity) rank
101 1 1 1
101 2 1 2
101 3 1 3
102 4 4 1
102 5 4 2
103 6 6 1
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On