LeetCode——Customers Who Never Order(灵活使用NOT IN以及IN)
程序员文章站
2023-11-09 20:44:34
此题,竟然一时间没想到如何合理的解决方案,主要是有较长的时间没有使用 与`NOT IN`. 也是一个手熟的活,需要经常锻炼,以下是解题答案: ......
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. +----+-------+ | id | name | +----+-------+ | 1 | joe | | 2 | henry | | 3 | sam | | 4 | max | +----+-------+ table: orders. +----+------------+ | id | customerid | +----+------------+ | 1 | 3 | | 2 | 1 | +----+------------+ using the above tables as example, return the following: +-----------+ | customers | +-----------+ | henry | | max | +-----------+
此题,竟然一时间没想到如何合理的解决方案,主要是有较长的时间没有使用in
与not in
.sql
也是一个手熟的活,需要经常锻炼,以下是解题答案:
# write your mysql query statement below select customers.name as customers from customers where customers.id not in (select customerid from orders)
上一篇: 10 个经典PHP函数