0
点赞
收藏
分享

微信扫一扫

Zookeeper 集群节点实现通信原理(一)

c一段旅程c 2024-06-24 阅读 29

183. Customers Who Never Order

Table: Customers

±------------±--------+
| Column Name | Type |
±------------±--------+
| id | int |
| name | varchar |
±------------±--------+
id is the primary key (column with unique values) for this table.
Each row of this table indicates the ID and name of a customer.

Table: Orders

±------------±-----+
| Column Name | Type |
±------------±-----+
| id | int |
| customerId | int |
±------------±-----+
id is the primary key (column with unique values) for this table.
customerId is a foreign key (reference columns) of the ID from the Customers table.
Each row of this table indicates the ID of an order and the ID of the customer who ordered it.

Write a solution to find all customers who never order anything.

Return the result table in any order.

The result format is in the following example.
 

Example 1:

From: LeetCode
Link: 183. Customers Who Never Order


Solution:

Ideas:
  1. LEFT JOIN is used to join the Customers table with the Orders table. This will include all rows from the Customers table and the matching rows from the Orders table.
  2. The WHERE O.customerId IS NULL clause filters out customers who have placed orders (i.e., those who have matching rows in the Orders table).
Code:
SELECT C.name AS Customers
FROM Customers C
LEFT JOIN Orders O ON C.id = O.customerId
WHERE O.customerId IS NULL;
举报

相关推荐

0 条评论