Creating Views in MySQL
📖 Scenario: You work at a bookstore that keeps track of books and their sales in a database. You want to create a simple way to see the best-selling books without writing complex queries every time.
🎯 Goal: Build a MySQL view named best_sellers that shows the book_id, title, and total_sales for books with more than 100 sales.
📋 What You'll Learn
Create a table named
books with columns book_id (integer), title (varchar), and sales (integer).Insert exactly three books with these values: (1, 'Learn SQL', 150), (2, 'Python Basics', 90), (3, 'Database Design', 200).
Create a view named
best_sellers that selects book_id, title, and sales as total_sales from books where sales is greater than 100.💡 Why This Matters
🌍 Real World
Views help simplify complex queries and provide easy access to filtered or summarized data in business databases.
💼 Career
Database developers and analysts often create views to improve data accessibility and maintainability in real projects.
Progress0 / 4 steps