题目:
Table: Customers
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
+-------------+---------+
id is the primary key column 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 for this table.
customerId is a foreign key 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 an SQL query to report all customers who never order anything.
Return the result table in any order.
给定两个table,一个是消费者资讯,一个是订单资讯
找出没点过东西的消费者
SELECT name as CustomersFROM CustomersLEFT JOIN Orders ON Customers.id = Orders.customerIdWHERE Orders.customerId IS NULL;
将两个table结合,条件订消费者id和订单消费者id相等
记得用left join这样未达成条件的人customerId才会是NULL
之后将customerId是NULL的人选出就好
最后执行时间377ms(faster than 98.66%)
那我们下题见