Open
Description
The SQL query you provided has a few syntax errors and logical issues that need to be corrected
SELECT co.country_name, COUNT(*) AS number_of_invoices, AVG(i.total_price) AS average_total_price FROM country co JOIN city ci ON co.id = ci.country_id JOIN customer cu ON ci.id = cu.city_id 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);
correction:
HAVING
Clause with Subquery:
The HAVING
clause now correctly uses a subquery to calculate the overall average total_price
from the invoice
table.
Metadata
Metadata
Assignees
Labels
No labels