From fc4a1c4f58bb288f384b44e705c08ab8451157f5 Mon Sep 17 00:00:00 2001 From: Suyash Singh Date: Fri, 3 Oct 2025 23:46:45 +0530 Subject: [PATCH] Update invoices-per-country.sql --- invoices-per-country.sql | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/invoices-per-country.sql b/invoices-per-country.sql index d094854..b4aeb01 100644 --- a/invoices-per-country.sql +++ b/invoices-per-country.sql @@ -1,5 +1,13 @@ -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 + c.country_name, + COUNT(i.id) AS total_invoices, + ROUND(AVG(i.total_price), 6) AS avg_invoice_amount +FROM country c +JOIN city ci ON ci.country_id = c.id +JOIN customer cu ON cu.city_id = ci.id +JOIN invoice i ON i.customer_id = cu.id +GROUP BY c.country_name +HAVING AVG(i.total_price) > ( + SELECT AVG(total_price) + FROM invoice +);