Answer: The GROUP BY Clause and the SUM Function
Explore how to use the SQL GROUP BY clause to group records and apply the SUM aggregate function to calculate total values per category. Understand the role of SELECT, FROM, aliases, and aggregate functions, and see alternate query methods like subqueries. This lesson prepares you to write efficient grouped queries and solve related interview problems.
Solution
The solution is given below:
Explanation
The explanation of the solution code is given below:
Line 2: The
SELECTquery selects theCategorycolumn and the total price of thePricecolumn by calculating it using theSUMfunction. We useASto set an alias for the column.Line 3: The
FROMclause specifies the table,Products. ...