Querying through Views
📖 Scenario: You work at a small bookstore that keeps track of book sales and customer information in a database. To make it easier for the sales team to get quick summaries, you want to create a view that shows total sales per customer.
🎯 Goal: Create a view named customer_sales_view that shows each customer's customer_id, customer_name, and their total sales_amount. Then write a query to select all data from this view.
📋 What You'll Learn
Create a table named
customers with columns customer_id (integer) and customer_name (text).Create a table named
sales with columns sale_id (integer), customer_id (integer), and amount (numeric).Insert the exact data provided into both tables.
Create a view named
customer_sales_view that joins customers and sales and sums the amount per customer.Write a query to select all columns from
customer_sales_view.💡 Why This Matters
🌍 Real World
Views help businesses create easy-to-use summaries of complex data, making it faster for teams to get insights without writing complicated queries every time.
💼 Career
Database developers and analysts often create and query views to improve data accessibility and performance in real-world applications.
Progress0 / 4 steps