Updating multiple rows with calculated values (distance by Pythagorean theorem)
Very confused been sat in front of this screen for 6 hours straight trying to figure this out - how do I update all rows with calculated data derived from the values in two other columns of the same record.
here's the situation:
I have a table called 'customers'. It had 4 columns - 'Customer_ID', 'Customer_Name', ' Coordinate_X' and 'Coordinate_Y'. since creating and filling the table with data I have added an empty 5th column called 'Distance'
What I'd like to do is fill the 'distance' column with the calculated distances from (0,0) to the locations specified in the 'Coordinate_X' and 'Coordinate_Y' columns of each row. I figured I could use Pythagoras's theory - and the correct values come up when I use the query:
Select SQRT(Power(customers.coordinate_x,2) + Power(customers.coordinate_y,2)) from customers
I fiddled about trying to make a trigger - failed that through lack of experience.
messed about trying to create a vie - failed that
Then I tried to fill the column using queries - failed that too.
I've been trying things like this;
update customers set distance = (Select SQRT(Power(customers.coordinate_x,2) + Power(customers.coordinate_y,2)) from customers)
Nothing's working - the best I'm getting is ORA-01427: single-row subquery returns more than one row
Any ideas?
Kind regards,
Neil