Good morning, I want to update my table, I want to add the net cost of my product and this net cost is the sum of my unit column + the freight column.
I'm doing the UPDATE like this:;
update com_entradas_produtos ep;
set ep.custo_item = sum(ep.unitario + ep.frete);
where ep.empresa = :empresa and ep.codigo = :codigo and ep.produto = :produto;
It is returning me the following error:
SQL error code = -104. Invalid aggregate reference.
Could you help me how should I do this update.
As Mark outlines in his comment above, aggregate functions like
SUM()are used to aggregate across rows, but it sounds like you want to just sum multiple columns on each row, so you want something like: