Jump to content

Average?


Tony

Recommended Posts

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.

 

db.jpg

 

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]

Link to comment
https://forums.phpfreaks.com/topic/108-average/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/108-average/#findComment-328
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/108-average/#findComment-334
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/108-average/#findComment-360
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.