您正在尝试计算不重复的行,但不使用
count(distinct ...)
SELECt COUNT(distinct c.id) as "Total Customers", COUNT(distinct p.id) as "Total Sales", COUNT(distinct c.id) * 1.00 / COUNT(distinct p.id) as "Sales per customer"FROM test_customers c LEFT OUTER JOIN test_purchases p ON c.id = p.cid
注意,性能不是很好



