SQL Analyzing Sales by Country

Screen Link: https://app.dataquest.io/m/191/guided-project%3A-answering-business-questions-using-sql/5/analyzing-sales-by-country

My Code:

WITH sub1 as (SELECT
customer.country country,
COUNT(customer.customer_id) number
FROM customer
GROUP BY 1
),

sub2 as (SELECT
il.invoice_id id, SUM(il.quantity) quantity
FROM invoice_line il
GROUP BY 1
)

SELECT
c.country,
sub1.number “number of customers”,
SUM(i.total) “total sales”,
CAST(SUM(i.total) as Float) / CAST(sub1.number as Float) “Avg value of customer”,
CAST(SUM(i.total) as FLOAT) / CAST(sub2.quantity as FLOAT) “Avg value of order”,
CASE
WHEN sub1.number > 1 THEN 2
ELSE 1
END as category
FROM customer c
INNER JOIN sub1 on sub1.country = c.country
INNER JOIN invoice i on i.customer_id = c.customer_id
INNER JOIN sub2 on sub2.id = i.invoice_id
GROUP BY 1 ORDER BY 2 DESC, 6 DESC

/* FYI - I know this is not fully completed as I need to create a view to categorize all the “other” countries *?

What I expected to happen:
I am not getting the right answer for “average order value”. Why is it by using sub2.quantity which is from invoice_line.quantity I am not getting the right answer, but using “distinct sub2.id” which is linked to invoice_line.invoice_id, I get the right answer?

Shouldnt they both lend the same answer?