首页 > 数据库技术 > 详细

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

时间:2020-06-04 01:07:35      阅读:44      评论:0      收藏:0      [点我收藏+]

题目

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

原文:https://www.cnblogs.com/coding-gaga/p/13040949.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!