Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何在游戏中只获得最高分数/记录';s每日排行榜,Rails 4+;博士后_Sql_Ruby On Rails_Postgresql_Activerecord - Fatal编程技术网

Sql 如何在游戏中只获得最高分数/记录';s每日排行榜,Rails 4+;博士后

Sql 如何在游戏中只获得最高分数/记录';s每日排行榜,Rails 4+;博士后,sql,ruby-on-rails,postgresql,activerecord,Sql,Ruby On Rails,Postgresql,Activerecord,我在Heroku上有一个Rails 4+Postgres后端的游戏。我们的每日排行榜显示了游戏中最高的100分。我们有一个用户模型和一个分数模型(用户有很多:分数) 它的工作原理与预期一样,如下所示: class Score < ActiveRecord::Base belongs_to :user def self.daily_leaders where(['created_at > ? and created_at < ?', Time.now.begin

我在Heroku上有一个Rails 4+Postgres后端的游戏。我们的每日排行榜显示了游戏中最高的100分。我们有一个用户模型和一个分数模型(用户有很多:分数)

它的工作原理与预期一样,如下所示:

class Score < ActiveRecord::Base
  belongs_to :user

  def self.daily_leaders
    where(['created_at > ? and created_at < ?', Time.now.beginning_of_day, Time.now.end_of_day]).order("points DESC").limit(100)
  end
end
class分数?和created_at<?',Time.now.start_of_day,Time.now.end_of_day])。订单(“积分描述”)。限额(100)
结束
结束
但是我们现在想更改它,使它只显示每个用户的最高分数。我已经尝试了各种附加的.select().distinct和.pulk ActiveRecord方法,但我总是遇到PG错误

就在今天,怎样才能获得每位用户的最高分数

class分数class Score < ActiveRecord::Base
  belongs_to :user

  def self.user_max_scores
    where('date(created_at) = ?', Date.today).select('user_id, max(points) as max_points').group(:user_id)
  end
end
属于:用户 def self.user_max_分数 其中('date(created_at)=?',date.today)。选择('user_id,max(points)as max_points')。组(:user_id) 结束 结束
好的,可以,但是如何包括其他列(如时间戳)?