I want to get the average of a column for the last 5 rows (if there are less than 5 rows (games) for a player then it should return nothing..)
If I could use a subquery then it would be straight forward, but since this isn't supported Im not sure how to approach it.
The sql below is what I have so far, this will get me the average for all games for each player if the player has played more than 5 games.
CREATE VIEW last_5_avg
AS
SELECT player, avg(score) FROM game_stats
JOIN games
ON games.id = games_stats.id GROUP BY player HAVING COUNT(games.id) > 4
ORDER BY games.id DESC;
Looks like the only way around this problem is to create a view for the last 5 game_stats of each player and then use a second view to do the averages.