表:customer
Customer number PRODUCT_ID
---------------- -----
12345 1
23456 2
12345 3
23456 3
12345 4
我需要创建一个查询,列出所有拥有2个或更多PRODUCT_ID>的客户。 2
答案 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