【SQL】LeetCode-Customers Who Never Order

LeetCode 183:Customers Who Never Order

【Description】

Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.

Table: Customers.
【SQL】LeetCode-Customers Who Never Order
Table: Orders.
【SQL】LeetCode-Customers Who Never Order
Using the above tables as example, return the following:
【SQL】LeetCode-Customers Who Never Order

【Solution】

Personal solution:

select name as customers
from customers as c
left join orders as o
on c.id =o.customerid
where o.id is null

Reference solution:

select customers.name as 'Customers'
from customers
where customers.id not in
(
    select customerid from orders
);
上一篇:《写给程序员的Python教程》阅读随笔---python禅学(Zen_of_python)


下一篇:mysql8.0.15二进制安装