PG :: GroupingError:错误:列“ books.id”必须出现在GROUP BY子句中或在聚合函数中使用

时间:2019-09-03 23:20:04

标签: ruby-on-rails activerecord ruby-on-rails-5

我有一个Book模型,该模型具有很多选票,我需要按多数选票将选票和顺序分组。

Book.where(status: :inactive, release: :coming_soon).joins(:votes).group("votes.book_id").order("count(votes.book_id) desc")

我收到此错误:PG::GroupingError: ERROR: column "books.id" must appear in the GROUP BY clause or be used in an aggregate function. I don't know to to solve it

0 个答案:

没有答案