SELECT s.score,
DENSE_RANK() OVER (ORDER BY s.score DESC) AS `rank`
FROM Scores s
窗口函数,rank()排序会跳,dense_rank不会,键盘左上角,那个键是转换键,类似于echo(linux)
SELECT DISTINCT num as ConsecutiveNums
FROM (
SELECT num,
LEAD(num, 1) OVER (ORDER BY id) AS next_num,
LEAD(num, 2) OVER (ORDER BY id) AS next_next_num
FROM Logs
) AS t
WHERE num = next_num AND num = next_next_num;
窗口函数lead的使用
SELECT
*
FROM
Employee AS a,
Employee AS b
WHERE
a.ManagerId = b.Id
AND a.Salary > b.Salary
;