Reorder records
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1383
Printed Date: 29 March 2026 at 10:15am Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: Reorder records
Posted By: pedalcars
Subject: Reorder records
Date 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?
------------- http://www.pedalcars.info/ - www.pedalcars.info
The most fun on four wheels
|
Replies:
Posted By: michael
Date 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.
|
Posted By: pedalcars
Date Posted: 27 March 2003 at 8:22am
Thanks, I'll give that a try.
------------- http://www.pedalcars.info/ - www.pedalcars.info
The most fun on four wheels
|
Posted By: pedalcars
Date 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
------------- http://www.pedalcars.info/ - www.pedalcars.info
The most fun on four wheels
|
Posted By: michael
Date 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
------------- http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker
|
Posted By: pedalcars
Date Posted: 27 March 2003 at 3:28pm
It's so simple when you know how...
Thanks again!
------------- http://www.pedalcars.info/ - www.pedalcars.info
The most fun on four wheels
|
|