MySql View with ranked rows -


i have view named "vw_season_score" returns result following query;

select s.* vw_season_one_score s 

query1result

if add query positions:

select  @currow := @currow + 1 position, s.* vw_season_one_score s join  (select @currow := 0) r 

enter image description here

however if try create view using following query...

create view vw_season_one_positions   select  @currow := @currow + 1 position, s.* vw_season_one_score s join  (select @currow := 0) r; 

i error:

error code: 1351. view's select contains variable or parameter 

so how can make view positions included ?

thanks in advance , taking time read this.

assuming ranking in order of score (you didn't include order by), , assuming 2 teams same score same rank, , assuming if have ranks 1, 2, 2, .. there no rank 3 , skip straight 4, can use following query potentially horribly performing, job done:

select *, 1 + (select count(score) vw_season_one_score t.score < score) rank   vw_season_one_score t   order score desc; 

you can use query basis view.

if there no duplicate scores, give nice rank of 1, 2, ..., n no repeats.

demo here


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -