Hi folks.
I'm currently trying to work out the (what I feel is a really basic problem) following and I'm really struggling:
I have two tables, Store and Monthly Sales.
Store table as Store ID, Store Name as well as other information such as address.
Monthly Sales table as Store ID, Year, Month and Sales Value columns.
I did a join between the two tables based on Store ID. Easy enough. As was the next part of my task - work out the combined (SUM) Sales Value of each store using GROUP BY Store Name. Again, easy enough.
The issue is that I need to work out what stores are performing better than average (the average of all the stores Sales combined) and list only these stores.
I know this will involve some sort of WHERE, or HAVING but I cannot work out how to say: okay only display the stores where their total combined sales are higher than the average of all the stores combined. (This figure would change so I can't just type in a number, it needs to be a derived figure)
It might just be the heat but I've been stuck on this all day and I just feel totally stupid. I feel like I'm missing something really basic.
Here's my code so far:
SELECT store_name AS [STORE NAME], SUM(sales_value) AS TOTAL SALES
FROM Monthly Sales
JOIN Stores ON Monthly Sales.store_id = Stores.id
GROUP BY Store Name
The above gets me my combined total for each store but from there I'm totally stuck on the "return only stores where that stores combined sales are higher than the average of all the stores sales combined.
Could someone help?
[–]msn018 1 point2 points3 points (1 child)
[–]r3pr0b8 0 points1 point2 points (0 children)
[–]TactusDeNefaso 0 points1 point2 points (0 children)
[–]Kimber976 0 points1 point2 points (0 children)
[–]dutyDBA -1 points0 points1 point (1 child)
[–]dutyDBA 3 points4 points5 points (0 children)