Skip to main content
Practice

8

sql

-- View all client orders
SELECT *
FROM client_orders;

-- Count how many unique clients placed orders
SELECT COUNT(DISTINCT client_id)
FROM client_orders;

-- Calculate average order value, but only using distinct order totals
SELECT AVG(DISTINCT order_total)
FROM client_orders;

-- Find the highest average order value by region using a subquery
SELECT MAX(avg_total)
FROM (
SELECT region, AVG(order_total) AS avg_total
FROM clients
JOIN client_orders ON clients.id = client_orders.client_id
GROUP BY region
) AS region_averages;

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.