Why does the next competitor place third after two tied winners?

RANK assigns the same place to ordering peers and advances the next place by the number of rows already seen.

SQLite example and interpretation

Scores nine, nine and six rank first, first and third. A unique ID inside the window would break the tie. Use it only for presentation when peers should share rank.

WITH s(id,v) AS (VALUES(1,9),(2,9),(3,6)) SELECT id,rank() OVER(ORDER BY v DESC) FROM s ORDER BY id;

Result [[1, 1], [2, 1], [3, 3]]

中文

两人并列第一时,下一名为什么是第三?

RANK 为同组排序键相同的行分配同一名次,下一组按前面已有的行数继续编号。

SQLite 示例与适用条件

分数 9、9、6 的名次是 1、1、3。在窗口排序里再加唯一 ID 会拆散原本的并列,应在外层安排展示顺序。

WITH s(id,v) AS (VALUES(1,9),(2,9),(3,6)) SELECT id,rank() OVER(ORDER BY v DESC) FROM s ORDER BY id;

结果 [[1, 1], [2, 1], [3, 3]]

References / 参考来源

Keep reading / 继续阅读