Jump to content

Archived

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

Master

Query question

Recommended Posts

I have a table with three records - player_id, year, and points.

 

Is there a way to compute a total points from point values stored in different records, in the initial query. Or do I need to execute a different query for every player, or add a total record for each player (call year 0000), and update both each time?

 

Example records.

 

player_id year points

 

1 2000 424

1 2001 313

2 2001 131

1 2002 242

2 2002 431

 

I want to return the total points for every player on the database. The number of years involved is a lot, so having all the years in the one record isn\'t really possible.

 

thanks

Share this post


Link to post
Share on other sites

Not sure what you\'re trying to do but here you go.

 

[php:1:06593fc386]<?php

SELECT TOTAL(points) AS Total FROM table;

?>[/php:1:06593fc386]

 

OR

 

[php:1:06593fc386]<?php

//Choose year range

$year_range = \'2001, 2002\';

 

SELECT TOTAL(points) AS Total FROM table WHERE (year IN (\".$year_range.\"));

 

?>[/php:1:06593fc386]

Share this post


Link to post
Share on other sites

×

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.