Hi,
I'm using MSSql 2005 on Windows 2003 Server.
I need some assistance to write a query to get the average of two columns and write the value to a third coulmn. All the transactions is in one table. Basically it is column 1 + column 2 devide by two = column 3
Thank you,
George
Software/Hardware used:
ASKED:
February 24, 2009 5:43 AM
UPDATED:
February 24, 2009 6:38 PM
Are you asking for a “statement” that sets the third column value to the average of the other two columns? That isn’t a “query” – you need to use an Update statement:
update mytable set column3 = (column1 + column2)/2;
A query does not change the values in the underlying tables.
Note – you may want to look at functions like “Round” or “Floor” if you want the average to be of a specified precision, or an integer value.
update mytable set column3 = round((column1+column2)/2, 2);