Choosing a column that fulfills many conditions in different records

前端 未结 2 1778
独厮守ぢ
独厮守ぢ 2021-01-24 07:54

I have got table like this:

+----------+---------+
| Customer | Product |
+----------+---------+
|        1 |       1 |
|        1 |       2 |
|        1 |               


        
2条回答
  •  旧时难觅i
    2021-01-24 08:43

    if you want the customer who bought all the 3 product you could use aggregation function count(distinct product)

        SELECT Customer
        FROM your_table
        where product in (1,2,3)
        GROUP BY Customer
        HAVING count(distinct product) = 3
    

提交回复
热议问题