Sql – Need help/suggestions for creating fantasy sports scoring databases and queries


I'm trying to create a website for my friends and I to keep track of fantasy sports scoring. So far, I've been doing the calculations and storage in Excel, which is very tedious. I'm trying to make it more simplified and automated through a SQL database that I can then wrap a web app around to enter daily stat updates.

It's premised on our participation in another commercial site where we trade virtual shares of athletes, and thus acquire an "ownership percentage" in each athlete. For instance, if there are 100 shares of AROD, and I own 10 shares, then I own 10%. It then applies this to traditional baseball rotisserie scoring. So, for instance, if AROD has 1 HR today, then his adjusted HR stat would be 1.10. If he also has 2 RBI's, then his adjusted RBI stat today would be 2.20, based on (2 x 1.10)(1 to normalize the stat, and the .10 to represent the ownership percentage).

All the stats for my team would then be summed each day and added to my stat history to come to an aggregated total. After that, points are allocated based on the ranking of each participant in each category at the end of the day. E.g. if there are 10 participants, and I have the highest total aggregate number of Adjusted HR's, then I get 10 pts. The points are then summed across the different stat categories to come up with a total point ranking for that day.

An added difficulty is that ownership %'s can change on a daily basis.

So far, in playing around with different schema, I don't know that having a separate table for each athlete's stats and each player's ownership %'s is the wisest choice. It seems to me that simply having two tables, one that contains the daily stat information for each athlete, and another that shows the ownership % of each player. My friend suggested using a start and end date for each ownership % to represent the potential daily changes in this category.

I'm admittedly new to database development, so any suggestions on query code would be appreciated.

Best Solution

You could go nuts, and do the following:

A table named 'Athletes' that has a record for each athlete. Here is where you could store the static properties of the athlete, like what sport they are in, their batting average, etc.

A table named 'Owners' that has a record for each user. This might include their name, their password hash, join date, etc.

A table for each athlete, containing a record for each owner. Here is where you'd store a reference to the Owners table, along with the percentage ownership.

A table for each owner, containing the history of ownership.