排名系统

LaPoPvLe 2009-04-10 03:11:03
现有问题如下:
用户表(tb_users)中包含用户信息(u_id,u_loginname等)
积分表(tb_permarks)中包含用户积分信息(u_id,u_marks等)
两者通过u_id关联
现在需要在用户属性中添加排名项,且会被经常访问
因为需要实时排名,在用户积分频繁变化的同时排名也会改变
考虑过用视图实现,但担心效率会成为负担
有没人做过类似的数据库设计
帮忙分析下,能给例子更好
【如有不清楚处,可跟帖,我会详细描述】
...全文
132 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
LaPoPvLe 2009-04-10
  • 打赏
  • 举报
回复
我再试下
欢迎大虾么多多赐教~~
LaPoPvLe 2009-04-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 sdhdy 的回复:]
SQL code
--排名
select a.u_id,a.u_loginname,px=(select count(1) from tb_permarks where u_id=b.u_id and u_marks>b.u_marks)+1 from tb_users a,tb_permarks b where a.u_id=b.u_id


[/Quote]
在多个排名条件的时候,不知道咋弄了
开始也用这个作为视图查询来排名的
还有效率方面呢?
sdhdy 2009-04-10
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 sdhdy 的回复:]
引用 6 楼 sdhdy 的回复:
SQL code--排名
select a.u_id,a.u_loginname,px=(select count(1) from tb_permarks where u_id=b.u_id and u_marks>b.u_marks)+1 from tb_users a,tb_permarks b where a.u_id=b.u_id

在表u_id列上都加上索引,可以做成视图。
[/Quote]

如果是聚焦索引,速度更快。
LaPoPvLe 2009-04-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 htl258 的回复:]
经常访问的列加上索引是可以.
[/Quote]
排名列现在还没生成(我开始用视图实现,该列在视图中存在)

sdhdy 2009-04-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 sdhdy 的回复:]
SQL code--排名
select a.u_id,a.u_loginname,px=(select count(1) from tb_permarks where u_id=b.u_id and u_marks>b.u_marks)+1 from tb_users a,tb_permarks b where a.u_id=b.u_id
[/Quote]
在表u_id列上都加上索引,可以做成视图。
sdhdy 2009-04-10
  • 打赏
  • 举报
回复
--排名
select a.u_id,a.u_loginname,px=(select count(1) from tb_permarks where u_id=b.u_id and u_marks>b.u_marks)+1 from tb_users a,tb_permarks b where a.u_id=b.u_id
LaPoPvLe 2009-04-10
  • 打赏
  • 举报
回复
大虾么~
能稍微详细点么
有以下情况:
1.用户的排名会被经常使用(查询)
2.用户有可能批量获取(排名页面)
3.排名标准可能有多个,有优先顺序,不允许重复排名

htl258_Tony 2009-04-10
  • 打赏
  • 举报
回复
经常访问的列加上索引是可以.
delphi_new 2009-04-10
  • 打赏
  • 举报
回复
做索引好点
Zoezs 2009-04-10
  • 打赏
  • 举报
回复
还是连接查询吧。做好索引。
Zoezs 2009-04-10
  • 打赏
  • 举报
回复
还是连接查询吧。做好索引。

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧