You need to have a link between the Sale and Customer tables. Presumably place Customer_ID in the Customer table as a primary key, and have Customer_ID in the Sale table be a foreign key. Assuming you do that, you can then run the below query.
SELECT
AVG(S.Sale_Total) Spent,
c.Cust_country
FROM
Sale S
INNER JOIN
Customer C on S.Customer_ID=C.Customer_ID
GROUP BY C.Cust_Country
This tells you the average amount spent, and the country where it was spent.
The key to understanding this answer is that AVG
(the average function) is an aggregate function, as it combines things. Often when you have an aggregate function, you have to group the other columns, hence why we included the GROUP BY
clause.
The reason you need Customer Id in the Customer table (apart from being the logical place for it) is so that you can establish a relationship between the Customer and Sale tables.
Another way to establish the relation is you can create a new table to link Customer and Sale together. Call it Customer Sales. For example:
Customer_Sales
Customer_Id
Sale_Id
Then you'd adjust the query to join based on that.