MySql View with ranked rows -
i have view named "vw_season_score" returns result following query;
select s.* vw_season_one_score s 
if add query positions:
select @currow := @currow + 1 position, s.* vw_season_one_score s join (select @currow := 0) r 
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.
Comments
Post a Comment