| Author |
Topic Search Topic Options
|
pedalcars
Senior Member
Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
|
Post Options
Thanks(0)
Quote Reply
Topic: Reorder records Posted: 26 March 2003 at 4:05pm |
|
Here's a git...
Multiple races in a year (8 in 2003!); Numerous teams who may or may not race all or fewer of those races and get some or more points at each, dependent on finishing position.
Just like any racing series really.
I have a results table, with all results and associated points for every race, which, for results pages, is filtered according to the desired race ID then ordered by the "finishing position" column. No problems there.
I also want to do a page for championship standings.
Now, quite simply I can filter the results table for all race IDs of the current year, then find all the results for team 1, add up the points, display them, move to team 2, do the same, etc.
However, this will give a final table ordered by team number and NOT (as I want) by points total and thus position.
The only way I can (so far) think of doing this is for the page to do the above adding up, then write the record back to a new "points total" table (which it would first need to empty from the last time it did this, ie, when someone else looked), repeat for all records, then reopen the "points total" table and order it by the total points.
And about ten days later, the server would finally compile the page and send it off down the wire.
And then fall over when, two seconds later, someone else asked it to do the same thing all over again.
Is there a way of doing this without using all the server resources on a single page?
If not, I'm thinking, include the summation / write to new table thing in an admin section, such that I could do it once, after new race results were added, then use that table for the points total page.
Any suggestions?
|
|
|
 |
michael
Senior Member
Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
|
Post Options
Thanks(0)
Quote Reply
Posted: 26 March 2003 at 4:49pm |
If you have a table like the following (example) RaceID TeamID DriverID Location Position Points You can get the total points for the team like so: SELECT TeamID, Sum(Points) AS SumOfPoints FROM Table GROUP BY TeamID And the Total Points for each Driver like so: SELECT DriverID, Sum(Points) AS SumOfPoints FROM Table GROUP BY DriverID
Just add a Order By clause whatever you want to order it by. If you elect to add fields, they need to be part of an aggregate function like sum, group etc. though.
|
 |
pedalcars
Senior Member
Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 March 2003 at 8:22am |
|
Thanks, I'll give that a try.
|
|
|
 |
pedalcars
Senior Member
Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 March 2003 at 2:26pm |
|
Michael,
After a few struggles, largely due to me being dim (!), it works!
Fantastic, someone else I owe beer to...
#
Editted additional:
Not wanting to be a pain, but is it possible to also get it to report on how many records it has "SUM"med to get to its result?
I want to show how many races each team has entered, plus in the event of a tie at season-end, the first deciding criteria is who attended the most events.
Ta
Edited by pedalcars
|
|
|
 |
michael
Senior Member
Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 March 2003 at 3:21pm |
|
Sure you just Count the DriverID's up as each Driver that had a race has an entry for each right? SELECT DriverID, Sum(Points) AS SumOfPoints,Count(DriverID) AS SumofRaces FROM Tablex GROUP BY DriverID
|
|
|
 |
pedalcars
Senior Member
Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 March 2003 at 3:28pm |
|
It's so simple when you know how...
Thanks again!
|
|
|
 |