PostgreSQL
 SQL >> Base de Dados >  >> RDS >> PostgreSQL

Rails: must appear in the GROUP BY clause or be used in an aggregate function

Ao selecionar agregados como SUM ou COUNT, as colunas não agregadas precisam constar na lista do GROUP BY.

ShopifyOrderLineItem.select( "shopify_order_line_items.title, count(shopify_order_line_items.id) as unique_ids, sum(amount) as total_price, sum(quantity) as total_quantity" ).where(:vendor_id => vendor_id) .group("shopify_order_line_items.title")

Garantir essa correspondência entre SELECT e GROUP BY resolve o erro.