Skip to content

Update invoices-per-country.sql #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions invoices-per-country.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
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 customer_count,
AVG(i.total_price) AS avg_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);