0
我想基於列是唯一在那裏我得到記錄運行軌道的查詢,在這種情況下,「ACCOUNT_ID」SELECT DISTINCT ON表達式必須初始ORDER BY表達式匹配
這完美的作品:
@comments = @store.comments.where(account_id: @selected_array).where(flagged: true).select('distinct on (account_id) *').paginate(:page => params[:page], :per_page => 30)
除訂單關閉外。當我試圖通過創建日期訂購:
@comments = @store.comments.where(account_id: @selected_array).where(flagged: true).select('distinct on (account_id) *').order("created_at DESC").paginate(:page => params[:page], :per_page => 30)
我得到的錯誤:
PG::InvalidColumnReference: ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressions
如何讓不同的部分,同時通過創建時間排序仍然有效?