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
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);
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: 1  Reply