Try below SQL:
CREATE TABLE new_table
AS
(
SELECT Product, Quantity, Price, (Quantity*Price) AS Total
FROM old_table
)
ANOTHER WAY:
ALTER TABLE old_table ADD COLUMN (Total Float);
UPDATE old_table SET Total = Quantity*Price;
Pregunta
I have a huge table and I would like to loop through each row, do the following calculation and insert the new value in a new column.
For example:
Old_Table1:
Product Quantity Price
TV 20 350€
New_Table:
Product Quantity Price TOtal
TV 20 350€ 7000€
How to write a query to do the following.
If anyone familiar with implementing the same with HANA then it would be great.
Solución
Try below SQL:
CREATE TABLE new_table
AS
(
SELECT Product, Quantity, Price, (Quantity*Price) AS Total
FROM old_table
)
ANOTHER WAY:
ALTER TABLE old_table ADD COLUMN (Total Float);
UPDATE old_table SET Total = Quantity*Price;
Otros consejos
One way is to use a cursor.
Here you can find more about it with example.