I have a table match
which looks like this (please see attached image). I wanted to retrieve a dataset that had a column of average values for home_goal
and away_goal
using this code
SELECT
m.country_id,
m.season,
m.home_goal,
m.away_goal,
AVG(m.home_goal + m.away_goal) AS avg_goal
FROM match AS m;
However, I got this error
column "m.country_id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 3: m.country_id,
My question is: why was GROUP BY
clause required? Why couldn't SQL know how to take average of two columns row by row?
Thank you.