わかりましたので、私はうまく機能し、このクエリを使用して起動します。Postgresの別のテーブルから集計機能を追加すること
SELECT org.organization_id, org.comp_code, org.name, cust.name as customer,
o.order_number as number, o.order_id as id, cast(o.total_charge as real) as receivable
FROM
organization as org, orders as o, organization as cust,
reconcile_order as ro
WHERE org.organization_id = o.shipper_org_id
and o.broker_org_id = cust.organization_id
and o.order_id = ro.order_id
and o.status = 'D'
and org.comp_code = 'ABC'
and (ro.receive_payment_in_full = 0 or ro.receive_payment_in_full is NULL)
しかし、今、私は、各ORDER_IDのために別のテーブルからの合計を追加します。この他の表はreconcile_receivablesと呼ばれ、amountという列があります。しかし、このトリックは、複数の金額が一意のorder_idに関連する可能性があるということです。だから、私はすべてのユニークな順序のためにこれらの金額を合計する必要があります。これは私が試したものです:助けないgroup by句を追加する
column "org.organization_id" must appear in the GROUP BY clause
or be used in an aggregate function
:
SELECT org.organization_id, org.comp_code, org.name, cust.name as customer,
o.order_number as number, o.order_id as id, cast(o.total_charge as real) as receivable,
sum(rr.amount) as partial_pay
FROM
organization as org, orders as o, organization as cust,
reconcile_order as ro, reconcile_receivables as rr
WHERE org.organization_id = o.shipper_org_id
and o.broker_org_id = cust.organization_id
and o.order_id = ro.order_id
and o.order_id = rr.order_id
and o.status = 'D'
and org.comp_code = 'ABC'
and (ro.receive_payment_in_full = 0 or ro.receive_payment_in_full is NULL)
私の問題は、私はこのエラーを取得しています。だから、どのo.order_idに関連するすべてのrr.amountの合計を表す列を表示するためにこれを解決することができますか?たとえば、合計が1000で、order_id = 3に関連する2つのrr.amount値があります。したがって、その行には合計額の列が1000の値で表示されます。
'Group by'で非集計カラムを追加します –