SectionΒ 2. ChapterΒ 2
single
Challenge: Top-Selling Products
Swipe to show menu
Task
Swipe to start coding
Write a query to list the top 3 products by total sales using a subquery in the FROM section.
- Use the
salestable to calculate the total sales for each product. - In a nested subquery inside the FROM section, group sales by
product_idand sum thetotal_amountfor each product. - Order the results by total sales in descending order and limit the output to the top 3 products.
- In the outer query, join this subquery result with the
productstable to get the product name and the total sales. - The result should display the product name and its total sales.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 2
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat