Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Reorder records
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Reorder records

 Post Reply Post Reply
Author
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post 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?
www.pedalcars.info

The most fun on four wheels

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Posted: 27 March 2003 at 8:22am
Thanks, I'll give that a try.
www.pedalcars.info

The most fun on four wheels

Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post 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
www.pedalcars.info

The most fun on four wheels

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Posted: 27 March 2003 at 3:28pm
It's so simple when you know how...

Thanks again!
www.pedalcars.info

The most fun on four wheels

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.