i’m trying to sum up values from one record (A) then add it to the sum values from another record (B), am wondering if this is possible?
ID ValueA ValueB ValueC
1 5 5 5
2 1 2 3
3 6 3 3
So what i’m trying to do here is to take ValueA, ValueB and ValueC of each record, adds it up so i can make an average.
So for
ID 1, i’ll have 15 divide by 3 = 5
ID 2 i’ll have 6 divide by 3 = 2
ID 3 i’ll have 12 divide by 3 = 4
then i will have to add all 3 of these up
i’ll get 11
and divide it by 3 and get an average of 3.67.
My Query
$result = mysql_query('SELECT * FROM teams WHERE UPPER(team)=UPPER("'.$team.'")');
while($row = mysql_fetch_array($result))
{
$ValueA = $row['ValueA'];
$ValueB = $row['ValueB'];
$ValueC = $row['ValueC'];
$All = $ValueA + $ValueB + $ValueC;
}
I know how to get the sum of 1 record, but not sure how can i do it with all 3 records. any help?
Edit : Sorry i forgot to add that i’ll have to do average on each record first.
should do the trick. Since you’re selecting all records from the table, there’s on grouping required.
Note that by default MySQL uses case-insensitive collations on tables, so your
UPPER(team)business might not be required – removing the function calls would allow indexes (if any) to be applied to that particular match.