0%

从不订购的客户


题目:

题解:

1、使用左连接

  • 解题思路:

  • sql语句:

    1
    2
    3
    4
    5
    select a.Name as Customers
    from Customers as a
    left join Orders as b
    on a.Id = b.CustomerId
    where b.CustomerId is null;

2、使用子查询和 NOT IN 子句

  • sql语句:

    1
    2
    3
    4
    5
    6
    select a.Name as Customers
    from Customers as a
    where a.id not in
    (
    select CustomerId from Orders
    );