How would I get a query that joins these four tables, and also gives me the average?
Table1:
TeamId | TeamName
1 | TA
2 | TB
3 | TC
Table2:
YearsId | Years
1 | 2009-2010
2 | 2010-2011
3 | 2011-2012
Table3:
MonthsId | Month
1 | July
2 | Aug
3 | Sept
Table4:
TeamId | MonthsId | YearsId | TeamWinCount
1 | 1 | 2 | 44
1 | 1 | 3 | 11
1 | 2 | 2 | 0
1 | 12 | 3 | 13
2 | 1 | 2 | 33
I would like to get results that look like this:
Year | Team | Avg (avg win count jun+aug+sept+.../12)
2009-2010 | TA | 23.3
2009-2010 | TB | 18.23
2009-2010 | TC | 35.23
2010-2011 | TA | 18.23
2010-2011 | TB | 18.23
2010-2011 | TC | 18.23
If there is no entry for a month, it should be counted as 0
There must be some genius out there’s that’s done this before. I’ve played around with joining the tables, but can’t seem to get a column that is the average. Any help or direction is much appreciated!
Table3is not needed here