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)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章