Jump to content


Photo

Average?


  • Please log in to reply
8 replies to this topic

#1 Tony

Tony
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 30 January 2003 - 06:18 PM

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.

Posted Image

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

#2 thejayjay

thejayjay
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 31 January 2003 - 01:38 AM

do you want to write a script to do it for you or do you want it to calculate it \"all by itself\"?

#3 Tony

Tony
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 31 January 2003 - 04:39 AM

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.

#4 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 31 January 2003 - 11:19 AM

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.../en/INSERT.html

P.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#5 Tony

Tony
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 31 January 2003 - 05:20 PM

Hmm, what do you mean by inserting the values before the calculations?

#6 Tony

Tony
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 01 February 2003 - 05:05 PM

Anyone know how to get that average?

#7 benW

benW
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationWaukesha WI

Posted 02 February 2003 - 01:47 AM

SELECT AVG(var1) , AVG(var2)  FROM  table




<?php str_replace("ASP", "PHP", $str); ?>

#8 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 03 February 2003 - 02:45 PM

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.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#9 Tony

Tony
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 09 February 2003 - 09:25 PM

thanks guys :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users