I have a couple queries on different tables where I do a group by to do some calcs. I would like to combine the queries in some way via a join or something. The calculations I do using "GROUP BY" complicates things (for me at least)
Here's a simplified description of the tables:
t1 is the tournament results table comprised of the fields: teamID, tournamentID, and points.
t2 is the team/year table I use to associate a teamID with the year or season that they participated and has the fields teamID and yearID.
The first query calculates the total points the team has accumulated in its career in the league.
The first query is as follows:
SELECT teamID, sum(points) AS Points FROM t1 GROUP BY teamID
The second query calculates how many years a team has participated in the league.
The second query is as follows:
SELECT teamID, count(teamID) AS Years FROM t2 GROUP BY teamID
Both queries produce an equal number of rows with every teamID in league history showing up once.
I would like to combine the two queries, teamID being equal in the two queries to have one result with the fields teamID, Years, Points.
Additionally, if possible in the same statement, I would like to add one more field being Points/Years to give an average.