diff --git a/invoices-per-country.sql b/invoices-per-country.sql index d094854..75a88e2 100644 --- a/invoices-per-country.sql +++ b/invoices-per-country.sql @@ -1,5 +1,7 @@ -SELECT co.country_name, count(*), AVG(i.total_price) -FROM country co, city ci, customer cu, invoice i -WHERE co.id = ci.country_id AND ci.id = cu.city_id AND cu.id = i.customer_id -GROUP BY co.country name -HAVING AVG(i.total_price) > (SELECT AVG(total price)) +SELECT co.country_name, COUNT(*) AS invoice_count, AVG(i.total_price) AS avg_total_price +FROM country co +INNER JOIN city ci ON co.id = ci.country_id +INNER JOIN customer cu ON ci.id = cu.city_id +INNER JOIN invoice i ON cu.id = i.customer_id +GROUP BY co.country_name +HAVING AVG(i.total_price) > (SELECT AVG(total_price) FROM invoice);