Sorting Customer Orders by Date and Amount
📖 Scenario: You work for an online store. You have a table of customer orders. Each order has a date and a total amount. You want to see the orders sorted first by the date they were placed, and then by the amount spent.
🎯 Goal: Create an SQL query that sorts the orders by order_date in ascending order, and if two orders have the same date, sort those by total_amount in descending order.
📋 What You'll Learn
Create a table called
orders with columns order_id (integer), order_date (date), and total_amount (decimal).Insert exactly three orders with these values: (1, '2024-01-10', 150.00), (2, '2024-01-10', 200.00), (3, '2024-01-09', 100.00).
Write a SELECT query to get all columns from
orders.Use
ORDER BY to sort by order_date ascending and then total_amount descending.💡 Why This Matters
🌍 Real World
Sorting data by multiple columns is common in reports, dashboards, and data analysis to organize information clearly.
💼 Career
Database developers and analysts often write queries with ORDER BY multiple columns to prepare data for business decisions.
Progress0 / 4 steps