This is a read-only copy of the MariaDB Knowledgebase generated on 2024-11-15. For the latest, interactive version please visit https://mariadb.com/kb/.

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.

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.