SELECT impressions.*
FROM impressions
WHERE impressions.user_id = 2
AND impressions.action_name = 'show'
AND (impressions.message IS NOT NULL)
GROUP BY impressionable_id, impressionable_type
我想從表中選擇那些在impressionable_id和impresssionable_type訂貨獨特的降ID的所有過去的印象,並獲得最後10排序方式上多列ID降序不同postrges
爲了解釋這種進一步
id, impressionabale_type, impressionable_id, action_name
50012, assignment, 2, show
50011, assignment, 1, show
50010, person, 1, show
50009, assignment, 1, show
50008, person, 5, show
50007, person, 4, show
50006, person, 3, show
50005, person, 1, show
50004, person, 1, show
50003, person, 2, show
50002, person, 2, show
50001, person, 1, show
50000, person, 1, show
理想我想這
50012, assignment, 2, show
50011, assignment, 1, show
50010, person, 1, show
50008, person, 5, show
50007, person, 4, show
50006, person, 3, show
50003, person, 2, show
我已經試過次方ct和group by但是我的sql知識最好是公平的。
我得到
PG::GroupingError: ERROR: column "impressions.id" must appear in the GROUP BY clause or be used in an aggregate function
有人可以提供一些線索,請
你有一些樣本數據嗎?也許一些理想的輸出呢? – verhie