Re: Large Calculations

From: Date: Mon, 30 Jul 2001 20:59:32 +0000
Subject: Re: Large Calculations
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-60278@lists.php.net to get a copy of this message
You wrote: > I have a mySQL database holding baseball stats and I want to calculate > rankings on these players. Now I'd obviously want this to be as fast as > possible since I go through about 600 players but where is it best to make > them? In the SQL command itself or in PHP? > > players need to have at least 100 at bats for this formula to work for them. > There are 6 steps. > > 1. batting average x .05 > 2. doubles + triples + HR divided by at bats > 3. runs scored divided by at bats > 4. rbi's divided by at bats > 5. stolen bases divided by at bats > next add up the 5 totals then multiply that total by 200. It's a bse 100 > system. a rating over 100 is very good. It all depends on how you're inserting the data. It really doesn't matter where you do the calculations. Math stuff is usually pretty fast when it's simple arithmetic. An SQL query such as this should be sufficient: update tablename set rating = ((avg * .05) + ((doubles + triples + homers) / abs) + (runs / abs) + (rbis / abs) + (sbs / abs)) * 200; Only problem here is, I'm not sure if SQL will do this on a record-by-record basis. If my thinking is wrong, you may end up with the same result for every record, because there's no "where" clause. You may have to sort that out yourself with some sort of loop. I guess selecting all those fields, and then doing the arithmetic for each record should suffice. HTH! :) -- -Ryan :: ICQ - 595003 :: GigaBoard - http://www.gigaboard.net/

« previous php.general (#60278) next »