Created
October 31, 2025 02:58
-
-
Save piti118/710416c5308d1e65fd68c16947fccb1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### SQL Question | |
| You are given the following three tables: | |
| **`customers`** | |
| | customer_id | name | | |
| |-------------:|-------------| | |
| | 1 | Alice | | |
| | 2 | Bob | | |
| | 3 | Charlie | | |
| **`orders`** | |
| | order_id | customer_id | order_date | | |
| |---------:|-------------:|-------------| | |
| | 101 | 1 | 2025-01-10 | | |
| | 102 | 2 | 2025-01-12 | | |
| | 103 | 1 | 2025-01-14 | | |
| **`order_items`** | |
| | item_id | order_id | product_name | quantity | price | | |
| |--------:|---------:|--------------|---------:|------:| | |
| | 1001 | 101 | Keyboard | 1 | 50 | | |
| | 1002 | 101 | Mouse | 2 | 25 | | |
| | 1003 | 102 | Monitor | 1 | 200 | | |
| | 1004 | 103 | Mouse | 1 | 25 | | |
| --- | |
| ### Question | |
| Write an SQL query to show **each customer’s total spending**, including customers who have not made any orders, sorted by the **highest spender first**. | |
| ### Example output | |
| | customer_name | total_spent | | |
| |---------------|-------------| | |
| | Alice | 125 | | |
| | Bob | 200 | | |
| | Charlie | 0 | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SQL Question
You are given the following three tables:
customersordersorder_itemsQuestion
Write an SQL query to show each customer’s total spending, including customers who have not made any orders, sorted by the highest spender first.
Example output