我正在嘗試執行一個查詢,該查詢返回購買單的信息,但也有另一個具有該單據詳細信息的表,但我需要將該總額添加到其他查詢,但是我不能添加列,因爲它說我需要在組中選擇相同的對象,並且我嘗試了這種方式,但它說它返回多個值。請幫助! :d將SUM列添加到查詢中
SELECT fc.fecha_factura_compra AS fecha, fc.id_factura AS no_factura, fc.serie,
o.abreviatura + CAST(p.corr_id AS VARCHAR(255)) AS codigo_trupp,
p.nombre, fc.dias_credito, fc.tipo_cambio,
(SELECT SUM(dc.peso_neto * dc.precio_unitario)
FROM detalle_compra AS dc
GROUP BY dc.id_proveedor,
dc.id_factura,
dc.serie) AS total
FROM factura_compra AS fc,
origen AS o,
proveedor AS p,
detalle_compra AS dc
WHERE fc.id_proveedor = p.id_proveedor
AND dc.id_proveedor = p.id_proveedor
AND dc.id_factura = fc.id_factura
AND p.id_origen = o.id_origen
AND dc.serie = fc.serie
AND dc.id_factura = fc.id_factura
AND dc.id_proveedor = fc.id_proveedor
AND fc.activo_inactivo = 'true'
AND fc.anulada = 'false'
請問您是否添加包含「group by」的查詢以及確切的錯誤消息呢? – vlood 2010-07-13 07:21:12
@ PedroC88 - 你會添加一個評論,解釋你爲什麼獎勵賞金?馬塞洛的答案不適合你嗎? – 2011-02-24 15:05:01
我收到以下錯誤:'列是無效的,因爲它不包含在聚合函數或GROUP BY子句中 –
PedroC88
2011-02-25 14:24:44