DATA ANALYTICS

๐Ÿ“ Interactive SQL Worksheet: Learn SQL for Data Analytics

Dataset Overview:

Assume weโ€™re working with two tables:

1. Customers

customer_idnamecountry
1Alice SmithUSA
2John LeeCanada
3Sara KhanUK

2. Orders

order_idcustomer_idorder_dateamount
10112024-12-01120.00
10222024-12-05150.00
10312024-12-09200.00

๐Ÿงช PART 1: Basic SELECT Queries

Q1. Write a query to get all customers from the table.

SELECT ___________ FROM customers;

Q2. Write a query to get the names of customers from the USA.

SELECT name FROM customers WHERE ___________ = 'USA';

๐Ÿงฎ PART 2: Aggregation

Q3. Write a query to find the total order amount.

SELECT ________(amount) FROM orders;

Q4. Get the average order amount.

SELECT _____________(amount) FROM orders;

๐Ÿ”— PART 3: JOINING Tables

Q5. Write a query to show all orders along with customer names.

SELECT o.order_id, c.name, o.amount  
FROM orders o  
JOIN customers c ON o.____________ = c.____________;

๐Ÿ“Š PART 4: GROUP BY and Filtering

Q6. Find total amount spent per customer.

SELECT c.name, SUM(o.amount) AS total_spent  
FROM orders o  
JOIN customers c ON o.customer_id = c.customer_id  
GROUP BY ________;

Q7. Show customers who have spent more than $200 in total.

-- Build on Q6 by adding:
HAVING SUM(o.amount) > ________;

๐Ÿš€ Challenge Question

Q8. List each country and the average amount spent by its customers.

SELECT c.country, AVG(o.amount) AS avg_spent  
FROM orders o  
JOIN customers c ON o.customer_id = c.customer_id  
GROUP BY ___________;

Leave a Reply

Your email address will not be published. Required fields are marked *