+----+-----------+--------+
| ID | username | score |
+----+-----------+--------+
| 1 | alice | 12 |
| 2 | bob | 22 |
+----+-----------+--------+
ID | username | score |
---|---|---|
1 | alice | 12 |
2 | bob | 22 |
+----+-----------------+----------------------+------------+----------+
| ID | gameTitle | gameTime | questions | answers |
+----+-----------------+----------------------+------------+----------+
| 1 | Football match | 2019-08-11 14:00:00 | {json} | {json} |
| 2 | Hockey game | 2019-07-11 15:00:00 | {json} | {json} |
+----+-----------------+----------------------+------------+----------+
ID | gameTitle | gameTime | questions | answers |
---|---|---|---|---|
1 | Football match | 2019-08-11 14:00:00 | {json} | {json} |
2 | Hockey game | 2019-07-11 15:00:00 | {json} | {json} |
+----+--------------+--------------+-------------+--------+-------+
| ID | gameID (FK) | userID (FK) | prediction | score | rank |
+----+--------------+--------------+-------------+--------+-------+
| 1 | 1 | 1 | {json} | 6 | 1 |
| 2 | 1 | 2 | {json} | 4 | 2 |
| 3 | 2 | 1 | {json} | 2 | 2 |
+----+--------------+--------------+-------------+--------+-------+
ID | gameID (FK) | userID (FK) | prediction | score | rank |
---|---|---|---|---|---|
1 | 1 | 1 | {json} | 6 | 1 |
2 | 1 | 2 | {json} | 4 | 2 |
3 | 2 | 1 | {json} | 2 | 2 |
I know I could do this manually by going through the Games table and getting all gameIDs that are in the given month, and then going through the Predictions table for all predictions with these IDs, and adding up the score for each user and then sending this. However, that seems crazily inefficient and resource-intensive. Especially considering that this will be an API call
One idea would be have to generate a new table for each month, and update and pull from this when relevant.
Another would be to have a 'monthly score' column in the User table, that resets each month. However, this wouldn't have historical data, which would be nice (though I guess could always be generated)