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
2
u/__agletesque Aug 01 '26
My initial idea was something like user DatabaseSpace suggested (I didn't mention anything about players table because if you kept track of goalscorers for both sides (what about own goals) you'd have to enter a lot of records into players table), so definitely separated (given the sub, normalized tables is the answer you'll get, and that's approach I'd take).
If you had one table for result and goalscorers, would you have reserved like 5+ columns for each week for goalscorers or would you alter table every time you need another column to put in another goalscorer. Also this approach would make it impossible to compare predicted data and goalscorers data, unless fixed number of goalscorers for each week, but don't do that.
Filtering tables is easy if you're worried about finding id to enter, just search about where clauses, and most likely like operator (and wildcard) or even regex, but I doubt that you'd need it.
Yeah, didn't mention for result, but I also agree with aforementioned user, go with view (prepared query).