Tony Posted January 30, 2003 Share Posted January 30, 2003 I have a a few columns containing numerical values. I want to have a column that would contain the average of some of these columns. I have a picture, maybe it\'ll explain it better. I would like the \"webave\" column to contain the averages of \"info\" and \"design\" columns. and I\'d like the \"totalave\" column to contain the average of \"skill\", \"activity\", \"pedi\" and \"webave\" columns. Is that even possible? I\'m a newbie at this database stuff so please be easy :? Regards, Tony[/img] Quote Link to comment Share on other sites More sharing options...
thejayjay Posted January 31, 2003 Share Posted January 31, 2003 do you want to write a script to do it for you or do you want it to calculate it \"all by itself\"? Quote Link to comment Share on other sites More sharing options...
Tony Posted January 31, 2003 Author Share Posted January 31, 2003 I want it to calculate \"all by itself\" The skill, activity, pedi, info and design values will be inserted from outside and when they are inserted I want mysql to input the average in the right column. I looked around and saw that there\'s an average function in mysql but with my low mysql skills I don\'t know how to use it. Quote Link to comment Share on other sites More sharing options...
pallevillesen Posted January 31, 2003 Share Posted January 31, 2003 If you just insert the other values before the calculations, then it can be done in sql. Like INSERT (\'Start\' = 5, \'End\' = 8, \'Distance\' = (End-Start) (this is pseudo pseudo sql... check the correct synax in the manual): Here\'s a little help from the manual: # An expression may refer to any column that was set earlier in a value list. For example, you can say this: mysql> INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2); Check the syntax: http://www.mysql.com/doc/en/INSERT.html P. Quote Link to comment Share on other sites More sharing options...
Tony Posted January 31, 2003 Author Share Posted January 31, 2003 Hmm, what do you mean by inserting the values before the calculations? Quote Link to comment Share on other sites More sharing options...
Tony Posted February 1, 2003 Author Share Posted February 1, 2003 Anyone know how to get that average? Quote Link to comment Share on other sites More sharing options...
benW Posted February 2, 2003 Share Posted February 2, 2003 SELECT AVG(var1) , AVG(var2) FROM table Quote Link to comment Share on other sites More sharing options...
pallevillesen Posted February 3, 2003 Share Posted February 3, 2003 Hmm, what do you mean by inserting the values before the calculations? I meant that in the VERY SAME statement you must specify the values first and then the calculations after... like insert into blabla (col1, col2, col3) values (4,4, average(col1, col2)); P. Quote Link to comment Share on other sites More sharing options...
Tony Posted February 9, 2003 Author Share Posted February 9, 2003 thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.