
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
注意,性能不是很好
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)