Jump to content

Newbie Question, Working With Data


Fred708

Recommended Posts

Hey!

This is probably a very easy question to answer, I honestly have no clue. I can work with the very basics of php and slight editing if the code is already there, but I have no clue really on how to go about this.

What I'm trying to do is add all the values stored in a particular column (about 840 values atm and growing), and hopefully divide that number by the total amount. (averaging it). I can do the displaying and such on my own, I have no idea how you would actually get all those numbers to add and such.

Any idea on how one could do this? Thanks for any help!
Link to comment
Share on other sites

welcome to the forums! hope you find lots of good help here.

to get averages, sums, and counts, you need to run aggregate functions in your SQL query. don't worry, it sounds a lot harder than it is! ;-)... if i want to find the sum of all the values in one column, i simply can select the SUM() of that column. for instance:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] [color=blue]SUM[/color](points) [color=green]AS[/color] points [color=green]FROM[/color] [color=orange]games;[/color] [!--sql2--][/div][!--sql3--]

that sql statement would return only one record containing a column called "points" that holds the value of all the records added together. same thing with average:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] [color=blue]AVG[/color](points) [color=green]AS[/color] points [color=green]FROM[/color] [color=orange]games;[/color] [!--sql2--][/div][!--sql3--]

hope that helps!
Link to comment
Share on other sites

Thanks for the quick reply, I appreciate it!

I'm sure that's what I want to be doing (fairly sure), but I can't seem to get it right.

The column I'm looking to average is item_value, which is in eqdkp_items, which is in the database eqdkp.

So how correct is this?

[code]$query="SELECT AVG(points) AS points FROM eqdkp_items";[/code] ?

I guess I'm having trouble going from eqdkp_items to item_value, which is the one I'd like to average.

Sorry, I'm clueless. Thanks again for the quick reply,
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.