= Solution
An <arithmetic mean> is <database aggregation>, which is outside classical <relational algebra>. Use <SQL>:
``
SELECT AVG(s.price) AS average_sale_price
FROM Sales AS s
JOIN Car AS c ON c.serialnumber = s.serialnumber
WHERE c.make = 'Saab';
``
For non-null prices $p_1,\ldots,p_n$ of qualifying sales, the result is
$$
\boxed{\overline p=\frac{p_1+\cdots+p_n}{n}\quad(n>0).}
$$
Each sale contributes once, even when a car was sold on several invoices. Do not use `DISTINCT` inside `AVG`: two different sales at the same price must both count. The car's <database primary key> makes the <relational join> match each sale to exactly one car, so the <relational join> introduces no extra weighting.
If there are no qualifying non-null prices, `AVG` returns <SQL NULL>. It ignores null prices if the implementation permits them; it does not replace an absent <arithmetic mean> with zero.<Aggregate Functions in the PostgreSQL documentation>[Section 9.21, `avg` and the paragraph on aggregates with no selected rows]{ref}
Back to article page