BFreshour
Programmer
- Mar 20, 2002
- 84
I run a gaming website, and I've ran into a small snag. We've had 2 seasons and all the stats are stored in one season. Something like this:
PK USER_FK SEASON_FK STAT
1 1 1 45
2 2 1 56
---
500 1 2 34
501 2 2 45
This table is linked to another table with player ratings (it looks at all the stats does some calculations to get the rating). It looks something like this:
PK USER_FK SEASON_FK RATING
1 1 1 23.45
2 2 1 45.23
---
500 1 2 42.12
501 2 2 22.32
Ok I think you get the idea. Of course the USER_FK and SEASON_FK link to other tables, one that has all the users, the other that has the seasons.
Now I have an overall rating graph that is currently averaging the ratings together (adding together / number of seasons). However, I'd like to do it a different way. The following formula is how I'd like to do it, but I can not figure out how to write the SQL query.
1 = season 1
2 = season 2
r = rating
t = player time
avg. rating = (R1 * (T1/T1+T2)) + (R2 * (T2/T1+T2))
---
It's pretty complex and I'm sure it takes some CASE statements but I simple can't figure it out... Any help would be appreciated.
PK USER_FK SEASON_FK STAT
1 1 1 45
2 2 1 56
---
500 1 2 34
501 2 2 45
This table is linked to another table with player ratings (it looks at all the stats does some calculations to get the rating). It looks something like this:
PK USER_FK SEASON_FK RATING
1 1 1 23.45
2 2 1 45.23
---
500 1 2 42.12
501 2 2 22.32
Ok I think you get the idea. Of course the USER_FK and SEASON_FK link to other tables, one that has all the users, the other that has the seasons.
Now I have an overall rating graph that is currently averaging the ratings together (adding together / number of seasons). However, I'd like to do it a different way. The following formula is how I'd like to do it, but I can not figure out how to write the SQL query.
1 = season 1
2 = season 2
r = rating
t = player time
avg. rating = (R1 * (T1/T1+T2)) + (R2 * (T2/T1+T2))
---
It's pretty complex and I'm sure it takes some CASE statements but I simple can't figure it out... Any help would be appreciated.