当前位置:Gxlcms > 数据库问题 > [LeetCode]1083. 销售分析 II(Mysql,having+if)

[LeetCode]1083. 销售分析 II(Mysql,having+if)

时间:2021-07-01 10:21:17 帮助过:33人阅读

题目

编写一个 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

[LeetCode]1083. 销售分析 II(Mysql,having+if)

标签:rod   and   销售   tco   _id   select   write   etc   statement   

人气教程排行