How do you safely calculate a ratio of two aggregates?

For each customer, calculate the share of their total order amount that comes from paid orders. Some transactions have zero amounts, refunds can have negative amounts, and some customers have no qualifying transactions at all. How would you write the SQL expression if the total amount could be zero? What should the metric return in that case, and why?

ExplainGROUP BY / HAVINGMiddleAnalystData EngineerBackendQA