r/learnSQL • u/AdvertisingOne7942 • Aug 01 '26
I need help creating a league table
So for a bit of context I have a football score prediction league where everyweek a number of players will tell me home_goals, away_goals, goal_scorer and this will be compared to the actual result of a Norwich City match. This is played over 46 games.
There is 3 points for the exact scoreline, 1 point for the correct result and 1 point for the correct goal scorer.
I can manually input everyones prediction and the result from Norwich each week.
But my problem is I am absolutely stuck on where or how to start to auto-populate or create the query to compare the results and give me an updated table after every game week.
Last season I made a python programme where I could semi easily set up the maths to accumulate over the season. Is this something that can be done on SQL or am I trying to do something that sql just isn't capable of doing?
Please any tips would be much appreciated. Oh and I am using Postgresql
View all comments
Show parent comment
1
u/AdvertisingOne7942 Aug 01 '26
I have been looking at having 1 table for the player inputs which will hold the primary key for each player and all of the fixed inputs that the player throughout the season so (player, gw1_home_goals, gw1_away_goals, gw1_goal_scorer - cont. with gw2, 3 etc)
A second table for the actual score which obviously will be updated after all the predictions are in this I was looking at (gw1_norwich_home_goals, gw1_norwich_away_goals, gw1_norwich_goal_scorer_1, norwich_goal_scorer_2 etc) (I am not sure what I would do with either primary or foreign keys here)
And a third table which is where I am at a loss is to create a query that will compare the 2 tables to end up with my final table which will have (player, games_played(this will just be a count), correct_score, correct_result, correct_goal_scorer, perfect(ie all 3 correct), total_points)
I have not thought about putting the goal_scorers in a separate table this was probably the hardest bit so do you think it would be better to separate.