码农专业户 2020-06-04
编写一个 SQL 查询,查询购买了 S8 手机却没有购买 iPhone 的买家。
使用having + sum+if,而不是自查询。
# Write your MySQL query statement below select buyer_id from Sales s join Product p on s.product_id = p.product_id group by buyer_id having sum(if(product_name=‘S8‘,1,0))>0 and sum(if(product_name=‘iPhone‘,1,0))=0