This is my first SQL query practice and I came up with this problem where I have to find an average of Quantity of items in stock from somewhere house that is greater than the average of a specific warehouse. All i got is a list of the warehouse with their average (the specific warehouse is not included) and I have to keep only the warehouse with its average that is greater than the average of that specific warehouse. How do I solve this? This is my first time learning SQL. Thank you
SELECT Warehouse, AVG(QuantityInStocks) AS Average
FROM SomeTable
WHERE Warehouse Not In ('Specific_Warehouse')
GROUP BY Warehouse;
Ivan Gerasimenko :
You should use subquery in HAVING clause:\n\nSELECT Warehouse, AVG(QuantityInStocks) AS Average\nFROM SomeTable\nWHERE Warehouse NOT IN ('Specific_Warehouse')\nGROUP BY Warehouse\nHAVING AVG(QuantityInStocks) > \n (SELECT AVG(QuantityInStocks) \n FROM SomeTable \n WHERE Warehouse IN ('Specific_Warehouse') \n GROUP BY Warehouse);\n",
2015-02-02T05:32:06