Compute points for the entire season using MySQL Database

Asked By 430 points N/A Posted on -
qa-featured

I want to make a column that can add the records together on my MySQL database. The record will add up the score of my entire league, taking the points from a race and add it with another race. The purpose of this is to compute the overall points of my entire league for one season. How can I possibly perform it?

SHARE
Best Answer by empressmau
Best Answer
Best Answer
Answered By 0 points N/A #104370

Compute points for the entire season using MySQL Database

qa-featured

You need to apply the Aggregate function sum to perform the addition in your MySQL query.

 

Just type in

SELECT SUM(score) as total_score FROM race;

For example, you name the column that contains the score of the entire league as 'total score' and  'race' . The command added all the values in the score field and displayed the total score.

The SUM command will add all the values of the score field and will create a new column that will show the total score for the entire league.


 

Answered By 0 points N/A #104371

Compute points for the entire season using MySQL Database

qa-featured

To get the total score of the entire league table, you have to identify the table name (such as league_table) and the column where you want to get the total from (such as race). The code to get the total can be as shown below assuming you are using php to connect to server:

<?php

$query="Select Sum(race) from league_table";

$result=mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_array($result));

{ echo "Total Score". "=" .$row['Sum(race)'];

   echo "<br>":

}

Thank you.

 

 

 

Related Questions