7
请教个查询排名 RANK 的 sql 写法
source link: https://www.v2ex.com/t/799971
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
SELECT userId, MIN(time), RANK() OVER (ORDER BY MIN(time) ASC) AS
"rank" FROM game WHERE a = 1 AND b = 2 AND c = 3 GROUP BY userId
这个 sql 能查出按 user 分组之后每个 user 最小的 time 和 rank,但是如果我想只查询其中某个 user 的 rank,应该怎么写呢?还是全部读取再自己 for 一遍?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK