什么是好的排名系统设计

发布于 2024-10-06 12:50:27 字数 191 浏览 0 评论 0原文

我有一个 USER 表,其中包含 userId 和 point 字段。在运行时,我想知道特定用户根据其观点的排名。实现这一目标的最佳方法是什么:
1:查询所有用户到列表中。根据点对列表进行排序,并进行二分搜索以查找该用户的排名。听起来这是个坏主意。
2:是否可以通过创建数据库查询来完成这些任务?

我预计有 2000-5000 个用户。

I have a USER table, that has userId and point fields. At runtime, I want to know what is a ranking of a particular user base on their point. What is the best way to accomplish this:
1: Query all users into a list. Sort the list base on point and do a binary search to find the ranking of that user. Sound like a bad idea here.
2: Is it possible to accomplish these tasks by creating database queries?

I expect 2000-5000 users.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老子叫无熙 2024-10-13 12:50:27
SET @rownum := 0;

SELECT rank, userId, point 
FROM (
       SELECT @rownum := @rownum + 1 AS rank, userId, point
       FROM user ORDER BY point DESC
     ) 
as result WHERE userId = xxxxxxxx
SET @rownum := 0;

SELECT rank, userId, point 
FROM (
       SELECT @rownum := @rownum + 1 AS rank, userId, point
       FROM user ORDER BY point DESC
     ) 
as result WHERE userId = xxxxxxxx
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文