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)
如对本文有疑问, 点击进行留言回复!!
MySQL-关系代数-并、交、差、等值连接、自然连接、左连接。。。
【MySQL牛客】10.获取所有非manager的员工emp_no
网友评论