数据库
首页 > 数据库> > 【SQL】LeetCode-Customers Who Never Order

【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.
在这里插入图片描述
Table: Orders.
在这里插入图片描述
Using the above tables as example, return the following:
在这里插入图片描述

【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
);

标签:Customers,Never,Who,customers,customerid,id,select
来源: https://blog.csdn.net/qq_41515531/article/details/112677062