我有以下代码:
SELECT rank, uid FROM
(SELECT @rownum := @rownum + 1 AS rank, t.uid, t.eid, e.uiDoB FROM aw_user_stats AS t
INNER JOIN aw_user_info AS e ON e.uid = t.uid
JOIN (SELECT @rownum := 0) r WHERE YEAR(e.uiDoB) = '1990'
ORDER BY t.usLevel DESC, t.usShuttles DESC) x WHERE x.uid = 35 ;
数据如下所示:
| uid | usLevel | usShuttle | uiDoB |
|----------------------------------------|
| 30 | 9 | 5 | 1990/05/01 |
| 32 | 7 | 8 | 1980/05/01 |
| 33 | 10 | 2 | 1990/05/01 |
| 34 | 4 | 1 | 1970/05/01 |
| 35 | 5 | 9 | 1985/05/01 |
如果我想要一个基于年龄给我最高的等级,除了id 30和33之外,它们都应该是第1,因为它们是唯一的。我测试了这个,因为它适用于这一行:
SELECT rank, uid FROM
(SELECT @rownum := @rownum + 1 AS rank, t.uid, t.eid, e.uiDoB FROM aw_user_stats AS t
INNER JOIN aw_user_info AS e ON e.uid = t.uid JOIN (SELECT @rownum := 0) r WHERE YEAR(e.uiDoB) = '1990'
ORDER BY t.usLevel DESC, t.usShuttles DESC) x ;
但我试图让它根据特定用户的出生年份显示排名。如果我用WHERE x.uid = 35
替换WHERE x.uid = 33
,它有两条记录(uiDoB年都是1990年),它首先告诉我它,因为它有更高的级别。使用uid = 30让我获得第二名。
但其余的没有给我记录。但因为它们是唯一应该首先出现的记录。但事实并非如此。我不明白为什么?