Using SQL query to find details of customers who ordered > x types of products

后端 未结 2 1714
生来不讨喜
生来不讨喜 2021-01-03 10:10

Please note that I have seen a similar query here, but think my query is different enough to merit a separate question.

Suppose that there is a database with the fol

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-03 10:51

    You could do it more simply:

    select
    
        c.id,
        c.cname,
        count(distinct o.pid) as `uniques`
    
    from o join c
    on c.id = o.cid
    
    group by c.id
    
    having `uniques` > 10
    

提交回复
热议问题