I have a table of values. I want another column which, for example, is thrice the first column plus one (or whatever other formula).
If I write something like this:
SELECT item, value, value*3+1 FROM myTable;
I get something like this:
A | 1 | 4
B | 2 | 7
C | 3 | 10
I want to store the third column permanently. Doing this:
ALTER TABLE myTable ADD COLUMN (value*3+1 AS value2 FLOAT);
Does not work. However, this does work:
CREATE TABLE myTable2 AS SELECT
item, value, value*3+1 AS value2
FROM myTable;
However, I don't want a new table, I want to insert a column into an existing table. I'm thinking I might need to ADD COLUMN
and then INSERT OVERWRITE
? Bonus points if your method can use UDFs like avg() or sum(), but I'll take just basic arithmetic for now.
I tried searching and neither this not this answered my question.