哪位顾客在我们的商店购买了4件或更多商品?

时间:2014-10-09 03:09:45

标签: sql count inner-join

哪位顾客在我们的商店购买了4件或更多商品?

SELECT cutomer.cusName, COUNT(itemName) AS 'Number of items'
FROM customer INNER JOIN store
ON customer.cusID = store.cusID
GROUP BY cutomer.cusName;

我不确定如何输出哪个顾客购买了4件或更多物品。

1 个答案:

答案 0 :(得分:0)

添加HAVING条款以吸引购买4件或更多商品的客户

SELECT cutomer.cusName, COUNT(itemName) AS 'Number of items'
FROM customer INNER JOIN store
ON customer.cusID = store.cusID
GROUP BY cutomer.cusName
HAVING count(itemName) >=4