Jump to content

Query question


Master

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

Link to comment
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]

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.