Re: Large Calculations

From: Date: Tue, 31 Jul 2001 07:27:05 +0000
Subject: Re: Large Calculations
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-60345@lists.php.net to get a copy of this message
> 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? Not even a close race: SQL will win every single time. Databases have been optimized to hell and back for DECADES to do this kind of stuff fast. PHP has only been alive for 5 years. You do the math :-) Not that PHP is slow, but SQL will win for sure. > 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. Not sure exactly which columns you have in your database, but do something not unlike this: select (hits/atbats * 0.05 + ((doubles + triples + homers)/atbats) + runs/atbats + stolen/atbats) * 200 as rating from players order by rating desc That's all 1 line, no matter what you see... For 600 hundred players, this isn't going to even be a burp on the system to do the work. -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#60345) next »