tbl_products
+-------+---------+---------+
| id | item | Customer|
+-------+---------+---------+
| 1 | Apple | brad |
| 2 | Apple | alex |
| 3 | Apple | brad |
| 4 | Apple | brad |
| 5 | Apple | tim |
| 6 | Orange | brad |
| 7 | Orange | steve |
| 8 | Orange | alex |
+-------+---------+---------+
有多少独特客户购买了苹果? 答案应该是: Apple 3
答案 0 :(得分:1)
试试这个:
SELECT COUNT(DISTINCT Customer)
FROM tbl_products
WHERE item ='Apple'