【问题标题】:Which customer has bought 4 or more items in our store?哪位顾客在我们的商店购买了 4 件或更多商品?
【发布时间】:2014-10-09 03:09:45
【问题描述】:

哪位客户在我们的商店购买了 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 件或更多商品。

【问题讨论】:

    标签: sql count inner-join


    【解决方案1】:

    添加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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 2014-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多