最适合高分列表的数据库类型

时间:2013-02-15 07:59:11

标签: mysql postgresql nosql

我正在开发一款需要存储在远程服务器上的高分系统的iPhone应用程序。

如果您在列表中排在第500位,则应在屏幕上看到第495至505位。

编辑(忘记提及此):您可以在多个列表中,例如“伦敦”,“超级英雄团队”和“小说粉丝”列表。如果有数百万用户和数千个群组,如何在我的所有列表中最有效地选择我的展示位置周围的10个位置?

我想到了以下内容:

  • 每个列表选择一个:select * from scores where list = '$list' order by points desc limit $myplace-5, 10
  • 为您的所有列表选择一个:select * from scores where list in ($lists) order by list, points desc,然后使用PHP选择正确的位置

显示所有新数据库类型(NoSQL等),是否存在适合此问题的数据库类型?

例如,从一开始就将得分插入正确的位置,以便每个select都不必对数据进行排序?

或者选择您所在地的10个地方的快捷方式? (如果我选择了正确的行,实际的排序可能发生在客户端)

2 个答案:

答案 0 :(得分:1)

最好的解决方案是使用SQL查询获取所需的确切数据,而不是通过PHP实现。使用NoSQL数据库可能不适合您的问题。 MySQL将毫无问题地处理这些数据。

答案 1 :(得分:0)

您可以直接通过以下查询获取订单

//user id
set @ID = 3; 

// get the score of the user
set @Score = (select score
              from users
              where ID = @ID);

//get the user who are less than you, and greather than you nad union them
select ID, Score
from (select U.ID, U.Score
      from users as U
      where U.ID <> @ID and
            U.Score < @Score
      order by U.Score desc limit 5) as P
union all
select U.ID, U.Score
from users U
where U.ID = @ID
union all
select *
from (select U.ID, U.Score
      from users as U
      where U.ID <> @ID and
            U.Score > @Score
      order by U.Score limit 5) as A
order by Score;   

src:https://stackoverflow.com/a/5796636/598424

相关问题