相关疑难解决方法(0)

PostgreSQL必须出现在GROUP BY子句中,或者用在聚合函数中

我在pg生产模式下收到此错误,但它在sqlite3开发模式下工作正常.

 ActiveRecord::StatementInvalid in ManagementController#index

PG::Error: ERROR:  column "estates.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT "estates".* FROM "estates"  WHERE "estates"."Mgmt" = ...
               ^
: SELECT "estates".* FROM "estates"  WHERE "estates"."Mgmt" = 'Mazzey' GROUP BY user_id

@myestate = Estate.where(:Mgmt => current_user.Company).group(:user_id).all
Run Code Online (Sandbox Code Playgroud)

postgresql production ruby-on-rails-3.1

26
推荐指数
4
解决办法
6万
查看次数

MySQL:获得用户的最高分

我有下表(高分),

id      gameid      userid      name      score      date
1       38          2345        A         100        2009-07-23 16:45:01
2       39          2345        A         500        2009-07-20 16:45:01
3       31          2345        A         100        2009-07-20 16:45:01
4       38          2345        A         200        2009-10-20 16:45:01
5       38          2345        A         50         2009-07-20 16:45:01
6       32          2345        A         120        2009-07-20 16:45:01
7       32          2345        A         100        2009-07-20 16:45:01
Run Code Online (Sandbox Code Playgroud)

现在在上述结构中,用户可以多次玩游戏,但我想显示特定用户的"游戏玩法".所以在游戏部分我不能展示多个游戏.因此,概念应该是如果用户玩了3次游戏,则应该显示具有最高分数的游戏.

我想要结果数据,如:

id      gameid      userid      name      score      date
2       39          2345        A         500        2009-07-20 16:45:01
3       31          2345        A         100        2009-07-20 16:45:01
4       38 …
Run Code Online (Sandbox Code Playgroud)

mysql sql

0
推荐指数
1
解决办法
8641
查看次数

标签 统计

mysql ×1

postgresql ×1

production ×1

ruby-on-rails-3.1 ×1

sql ×1