Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Top-Selling Products | Nested Subqueries in the FROM section
Generate Nested Subqueries in SQL
SectionΒ 2. ChapterΒ 2
single

single

bookChallenge: 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 sales table to calculate the total sales for each product.
  • In a nested subquery inside the FROM section, group sales by product_id and sum the total_amount for 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 products table to get the product name and the total sales.
  • The result should display the product name and its total sales.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt