Answer: The GROUP BY Clause and the SUM Function
Find a detailed explanation of using the GROUP BY clause to group the records using SQL query.
Solution
The solution is given below:
Press + to interact
/* The query to find the total price of products for each category */SELECT Category, SUM(Price) AS TotalPriceFROM ProductsGROUP BY Category;
Explanation
The explanation of the solution code is given below:
Line 2: The
SELECT
query selects theCategory
column and the total price of thePrice
column by calculating it using theSUM
function. We useAS
to set an alias for the column.Line 3: The
FROM
clause specifies the table,Products
.Line 4: ...