Leetcode-Mysql题目及知识点总结(183.从不订购的客户)

计算机小白QAQ,因为想找数分岗暑期实习所以充了会员想集中刷一下leetcode的mysql部分。写这个系列博文和大家们交流一下,后面也会持续更新面经准备的一些问题,欢迎同好们一起交流,求大佬轻喷QAQ。因为自己初学也走了很多弯路,所以会尽量写得详细一点,如果可以帮助到后来的朋友们,请各位留言鼓励一下哈哈哈哈。

183、从不订购的客户

思路1:利用左连接,将order中的customerid和customers中的id匹配,匹配不到的证明是没有购买东西的用户。

select Name as Customers

from Customers

left join Orders on Customers.Id=Orders.CustomerId

where Orders.Id is null

思路2:利用子查询,提取order中所有的customerid,customer表中id不在其中的即为没有购买东西的用户。

select Name as Customers

from Customers

where Id not in (select CustomerId from Orders)

猜你喜欢

转载自blog.csdn.net/weixin_43167461/article/details/113177507