MySQL Forums
Forum List  »  InnoDB

Re: Rank with Total
Posted by: Ra Nala
Date: November 06, 2017 12:01PM

Hi Peter Sir,

actually ,We are using many tables to get data so kindly check below query and if you are able to help on below 4th (rank_total) column (i.e. value= 3 should be for 3 rows based on rank order 1,2,3 then help me.

kindly ignore if it is not relevant for you.

SELECT
t.*,
@cur:= IF(id=@id, @cur+1, 1) AS RowNumber,
@id := id
FROM
t CROSS JOIN
(SELECT @id:=(SELECT MIN(id) FROM t), @cur:=0) AS init
ORDER BY
t.id

Data as like below

id | Name | rownumber | rank_total
1---- a ------- 1------- 3
1---- b --------2------- 3
1---- ads ----- 3------- 3

Thank you

Options: ReplyQuote


Subject
Views
Written By
Posted
1182
November 02, 2017 12:38PM
665
November 02, 2017 01:12PM
586
November 04, 2017 11:44AM
507
November 04, 2017 12:07PM
643
November 04, 2017 12:15PM
571
November 04, 2017 05:36PM
596
November 05, 2017 11:49AM
561
November 05, 2017 03:43PM
Re: Rank with Total
557
November 06, 2017 12:01PM
516
November 06, 2017 12:51PM


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.