假设我有一个包含以下列的表UserStatistics
:
UserId (UNIQUEIDENTIFIER)
ViewCount (BIGINT)
SubscriberCount (BIGINT)
Rank (INT)
- 为数据库中的数百万用户提供 1-10 或 1-5 排名的最佳方式是什么?
- 您会推荐什么? 1-10 或 1-5 还是其他?为什么?
编辑:
我希望对 SubscriberCount
给予比 ViewCount
更多的重视
最佳答案
要计算排名,您可以使用 ntile像这样。
select *,
ntile(5) over(order by ViewCount+SubscriberCount) as CalculatedRank
from UserStatistics
如果您希望排名值为 1-10 以及 SubscriberCount
的权重更大,您可以像这样修改查询。
select *,
ntile(10) over(order by ViewCount+SubscriberCount*2) as CalculatedRank
from UserStatistics
关于c# - 计算用户排名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5695400/