> 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 [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to