Professional Documents
Culture Documents
Get a list of all customers and their total orders amount, sorted by the highest total
orders amount first.
Get a list of all customers who have not placed any orders.
SELECT c.customer_name
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;
Get a list of all customers and the total amount of their orders, including customers who
have not placed any orders yet.
Get a list of all customers who have placed at least one order with a total amount
greater than $100.
SELECT customer_name
FROM customers
WHERE customer_id IN (SELECT customer_id FROM orders WHERE total_amount >
100);
Get a list of all orders placed by customers who live in the same city as customer "John
Smith".
SELECT order_number
FROM orders
WHERE customer_id IN (SELECT customer_id FROM customers WHERE city = (SELECT
city FROM customers WHERE customer_name = 'John Smith'));
Get a list of all customers who have not placed any orders.
SELECT customer_name
FROM customers
WHERE customer_id NOT IN (SELECT customer_id FROM orders);
Get a list of all customers and their orders, along with the total number of orders they
have placed.
Get a list of all customers and their orders, along with the maximum total amount of
orders for customers who have placed at least one order.