rtvalluri rtvalluri - 2 months ago 16
SQL Question

Multiplying two columns of same table and storing result to the third column of same table

I m having a table

SALES(sno,comp_name,quantity,costperunit,totalcost)


After supplying the
costperunit
values,
totalcost
need to be calculated as
"totalcost=quantity*costperunit".


I want to multiply
'quantity'
and
'costperunit'
columns and store the result in
'totalcost'
column of same table.

I have tried this:

insert into SALES(totalcost) select quantity*costperunit as res from SALES


But It failed!

Somebody please help me in achieving this..
Thanks in Advance

Answer

You need to use update.

UPDATE SALES SET totalcost=quantity*costperunit
Comments