Answer: Aggregate Records Using AVG
Explore the use of the SQL AVG function to compute average prices grouped by category. Understand how to apply aggregate functions, set aliases, and use GROUP BY clauses effectively to summarize data. This lesson also discusses alternate solutions like JOINs and highlights common pitfalls when filtering with aggregates.
Solution
The solution is given below:
Explanation
The explanation of the solution code is given below:
Line 2: The
SELECTquery selects theCategorycolumn and the average price of thePricecolumn by calculating it using theAVGfunction. We useASto set an alias for the column.Line 3: The
FROMclause specifies the table,Products. ...