Order Value per Region
Please assist. I would like to answer this question: "What is the average order value in the African Region per month?"
My Data Model(https://drive.google.com/file/d/1mXQpAl_m02ZtGzxNk2L_vFPCySzMR7qh/view?usp=sharing)
sample-data-tpch-schema
My Code:
SELECT Avg(Orders) AS Order Value
FROM Orders, Customer, Nation, Region
Join Customer AS C
ON Customer.Custkey = Orders.Custkey
Join Customer AS C ON Customer.Nationkey=Nation.Nationkey
Join Nation.Nationkey=Region.Nationkey
where Region = Africa
Answer Answered by Daniel Black in this comment.
When you "JOIN" tables like this (and recommended syntax) don't list all the tables on the "FROM" line (avoid ever doing a "," join on the FROM line). The only table needed in the FROM clause is "Orders".
Apart from that to perform aggregates, a GROUP BY is usually needed though in this case i think its implicit.