I'm doing a Query where I add the amount of products that I have after multiplying it ..
This is the Query.
declare @Sucursalid int
set @Sucursalid = 1
SELECT i.sucursalid as SucursalID,( COUNT(p.id) * p.pesomililitros) AS Cantidad
FROM inventario AS i
INNER JOIN productos AS p ON i.productoid = p.id
WHERE i.sucursalid = @Sucursalid AND i.consumido = 0 AND ( i.copeo IS NULL OR i.copeo IS NOT NULL ) AND i.copeo = 1
GROUP BY I.sucursalid, p.pesomililitros
When it should be like this ..
SucursalID Cantidad
1 2950
I hope you understand. Thanks.
Structure of the product table.
In itself, the value of pesomililitros can be different. 750ml 700ml 695ml
tells me this error. if I add sum(( COUNT(p.id) * p.pesomililitros)) AS Cantidad
In the selection of sql ...
cannot perform an aggregate function on an expression containing an aggregate or a subquery