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
All you need to do is use the multiplication operator (*) between the two multiplicand columns ( price * quantity ) in a simple SELECT query. You can give this result an alias with the AS keyword; in our example, we gave the multiplication column an alias of total_price .
For example, to multiply values in columns B, C and D, use one of the following formulas: Multiplication operator: =A2*B2*C2. PRODUCT function: =PRODUCT(A2:C2) Array formula (Ctrl + Shift + Enter): =A2:A5*B2:B5*C2:C5.
Try updating the table
UPDATE SALES SET totalcost=quantity*costperunit
You need to use update.
UPDATE SALES SET totalcost=quantity*costperunit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With