Answer: Subquery and Calculations
Explore how to write and understand SQL queries using subqueries and aggregate functions like AVG. This lesson helps you master filtering data based on calculated conditions and alternative subquery techniques to solve interview problems efficiently.
Solution
The solution is given below:
Explanation
The explanation of the solution code is given below:
Line 2: The
SELECTquery selects theProductNameandCategorycolumns from theProductstable. TheProductstable has been given an aliaspfor easy referencing.Line 3: The
WHEREclause applies the condition that sales ofUnitsSoldis greater than the result of the subquery.Line 4: The subquery returns the calculated average of all units sold of the products. ...