Mysql
 sql >> Datenbank >  >> RDS >> Mysql

PHP MYSQL-Gruppenranking-Abfrage

Sie müssen die where-Klausel innerhalb der Abfrage als

verschieben
SELECT pid, 
name, 
age, 
team, 
rank 
FROM (
 SELECT pid, name, age, team,
 @curRank := IF(@prevRank = age, @curRank, @incRank) AS rank, 
 @incRank := @incRank + 1, 
 @prevRank := age
 FROM players p, (SELECT @curRank :=0, @prevRank := NULL, @incRank := 1) r
 WHERE team='aa'
 ORDER BY age DESC
) s