Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个名为“points”的表,其中有一个“total”字段,其中包含一条记录的总点数。现在我想计算特定记录的排名。
就像:SELECT (...) as rank FROM points WHERE id=63
SELECT (...) as rank FROM points WHERE id=63
这在 SQL 中可能吗?
计算点数较高的行 + 1 和总行数。
SET @rownum := 0; SELECT rank, total FROM ( SELECT @rownum := @rownum + 1 AS rank, total, id FROM points ORDER BY total DESC ) as result WHERE id=63