Jump to content


Photo

Query question


  • Please log in to reply
1 reply to this topic

#1 Master

Master
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 14 March 2003 - 03:19 PM

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

#2 benW

benW
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationWaukesha WI

Posted 15 March 2003 - 03:21 AM

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]


<?php str_replace("ASP", "PHP", $str); ?>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users