当前位置: 首页 > news >正文

力扣之183.从不订购的客户

1. 183.从不订购的客户

1.1 题干

Customers 表:

±------------±--------+
| Column Name | Type |
±------------±--------+
| id | int |
| name | varchar |
±------------±--------+
在 SQL 中,id 是该表的主键。
该表的每一行都表示客户的 ID 和名称。
Orders 表:

±------------±-----+
| Column Name | Type |
±------------±-----+
| id | int |
| customerId | int |
±------------±-----+
在 SQL 中,id 是该表的主键。
customerId 是 Customers 表中 ID 的外键( Pandas 中的连接键)。
该表的每一行都表示订单的 ID 和订购该订单的客户的 ID。

找出所有从不点任何东西的顾客。

以 任意顺序 返回结果表。

结果格式如下所示。

示例 1:

输入:
Customers table:
±—±------+
| id | name |
±—±------+
| 1 | Joe |
| 2 | Henry |
| 3 | Sam |
| 4 | Max |
±—±------+
Orders table:
±—±-----------+
| id | customerId |
±—±-----------+
| 1 | 3 |
| 2 | 1 |
±—±-----------+
输出:
±----------+
| Customers |
±----------+
| Henry |
| Max |
±----------+

1.2 准备数据

Create table If Not Exists Customers (id int, name varchar(255))
Create table If Not Exists Orders (id int, customerId int)
Truncate table Customers
insert into Customers (id, name) values ('1', 'Joe')
insert into Customers (id, name) values ('2', 'Henry')
insert into Customers (id, name) values ('3', 'Sam')
insert into Customers (id, name) values ('4', 'Max')
Truncate table Orders
insert into Orders (id, customerId) values ('1', '3')
insert into Orders (id, customerId) values ('2', '1')

1.3 解法

select c.name Customers from Customers c left join Orders o on c.id=o.id where c.id not in (select customerId from Orders);

1.4 结果截图

在这里插入图片描述


http://www.mrgr.cn/news/33287.html

相关文章:

  • 软件测试APP测试过程中的关键步骤、工具使用及常见问题处理方法。
  • MySQL篇(事务 - 基础)
  • 【LLM】Ollama:本地大模型使用
  • 从编辑器到自动化脚本,提高编程效率的必备工具秘籍
  • 【C语言】const char*强制类型转换 (type cast)的告警问题
  • Qt 每日面试题 -2
  • react:React Hook函数
  • 华为OD机试真题-IPv4地址转换成整数-2024年OD统一考试(E卷)
  • 打开C嘎嘎的大门:你好,C嘎嘎!(2)
  • 语言RPA流程组件介绍--获取网页信息
  • 上位机图像处理和嵌入式模块部署(linux小系统开发)
  • 字符串 下【KMP再续】
  • GitHub每日最火火火项目(9.22)
  • 【Elasticsearch系列十八】Ik 分词器
  • 解锁电商新视野:京东商品详情API——您的精准商品信息探索利器
  • Java后端中的延迟队列实现:使用Redis与RabbitMQ的不同策略
  • AI学习指南深度学习篇-Adadelta简介
  • JavaScript(二)
  • 【Linux 从基础到进阶】 AWS云服务在Linux上的应用
  • C\C++内存管理详解