SQL - 需要帮助创建查询

时间:2017-10-23 23:35:19

标签: sql

表:customer

Customer number          PRODUCT_ID            
----------------         -----             
12345                    1            
23456                    2            
12345                    3
23456                    3
12345                    4        

我需要创建一个查询,列出所有拥有2个或更多PRODUCT_ID>的客户。 2

1 个答案:

答案 0 :(得分:0)

select c.customer_number, count(c.product_id) as product_count
from customer c
group by c.customer_number
having count(c.product_id) > 2

您应该阅读有关如何将HAVING子句与聚合函数结合使用的解释:https://www.w3schools.com/sql/sql_having.asp

相关问题