MySQL Forums
Forum List  »  MySQL Query Browser

Generate a sequence number based upon a ORDER BY column
Posted by: penn rabb
Date: September 30, 2014 03:02PM

I have a query that works and I am trying to build a rank column. Consider the query:

SELECT item,weight,group_id FROM table ORDER BY group_id ASC, weight DESC

I have the following data displayed:

item,weight,group_id
Table,150,1
Chair,75,1
Lamp,3,1
Bookcase,200,2
Cabinet,150,2
Ladder,15,2
Server,40,3
Monitor,15,3
Keyboard,2,3

What I want to do is build a group_rank column with a sequence number according to group_id and the descending weight such that:

item,weight,group_id,group_rank
Table,150,1,1
Chair,75,1,2
Lamp,3,1,3
Bookcase,200,2,1
Cabinet,150,2,2
Ladder,15,2,3
Server,40,3,1
Monitor,15,3,2
Keyboard,2,3,3

o sql gurus hear my plea...

Options: ReplyQuote


Subject
Written By
Posted
Generate a sequence number based upon a ORDER BY column
September 30, 2014 03:02PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.