美文网首页
2020-04-10

2020-04-10

作者: DUYAN_bc77 | 来源:发表于2020-04-10 10:47 被阅读0次

    查询从不

    某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。

    Screen Shot 2020-04-10 at 9.54.50 AM.png

    Solution 1

    *LEFT JOIN,IS NULL*
    SELECT Name as Customers FROM Customers
    LEFT JOIN Orders 
    ON Customers.Id=Orders.CustomerId
    WHERE Orders.Id IS null;
    

    左连接,结果晒选不为空的 “IS null”

    Solution 2

    *NOT IN* 
    Select name as Customers
    From Customers
    Where id not in (select CustomerId from orders)
    

    相关文章

      网友评论

          本文标题:2020-04-10

          本文链接:https://www.haomeiwen.com/subject/piylmhtx.html