How do you avoid double-counting when aggregating after a JOIN?

You have an orders table containing an order total and a separate table of order items. Each order can contain multiple items. For each customer, you need to calculate the number of orders, the combined order total, and the number of units sold. Explain why a JOIN followed by aggregation can inflate these figures. How would you structure the query to get accurate totals and counts? Why doesn't SUM(DISTINCT total) always fix the problem?

ExplainGROUP BY / HAVINGSeniorAnalystData EngineerBackend