سؤال

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.

هل كانت مفيدة؟

المحلول

Try below SQL:

CREATE TABLE new_table 
AS 
(
SELECT Product, Quantity, Price, (Quantity*Price) AS Total 
FROM old_table
)

SQL Fiddle

ANOTHER WAY:

ALTER TABLE old_table ADD COLUMN (Total Float);

UPDATE old_table SET Total = Quantity*Price;

SQL Fiddle 2

نصائح أخرى

One way is to use a cursor.

Here you can find more about it with example.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top