Using Subqueries in FROM Clause (Derived Tables) in PostgreSQL
📖 Scenario: You work for a small bookstore that keeps track of book sales. You want to analyze sales data to find the total sales per author and then find authors with total sales above a certain amount.
🎯 Goal: Build a SQL query using a subquery in the FROM clause (a derived table) to calculate total sales per author, then filter authors with total sales greater than 100.
📋 What You'll Learn
Create a table called
sales with columns book_id, author, and copies_sold.Insert the exact sales data provided into the
sales table.Write a subquery in the FROM clause that sums
copies_sold grouped by author.Use the derived table to select authors with total sales greater than 100.
💡 Why This Matters
🌍 Real World
Analyzing sales data by grouping and filtering is common in business reporting and decision making.
💼 Career
Knowing how to use subqueries in the FROM clause helps you write clear and efficient SQL queries for data analysis roles.
Progress0 / 4 steps