当前位置:网站首页>2022.07.12_Daily Question
2022.07.12_Daily Question
2022-07-31 07:39:00 【No. い】
175. 组合两个表
题目描述
表: Person
+-------------+---------+
| 列名 | 类型 |
+-------------+---------+
| PersonId | int |
| FirstName | varchar |
| LastName | varchar |
+-------------+---------+
personId 是该表的主键列.
该表包含一些人的 ID 和他们的姓和名的信息.
表: Address
+-------------+---------+
| 列名 | 类型 |
+-------------+---------+
| AddressId | int |
| PersonId | int |
| City | varchar |
| State | varchar |
+-------------+---------+
addressId 是该表的主键列.
该表的每一行都包含一个 ID = PersonId 的人的城市和州的信息.
编写一个SQL查询来报告 Person
表中每个人的姓、名、城市和州.如果 personId
的地址不在 Address
表中,则报告为空 null
.
以 任意顺序 返回结果表.
查询结果格式如下所示.
示例 1:
输入:
Person表:
+----------+----------+-----------+
| personId | lastName | firstName |
+----------+----------+-----------+
| 1 | Wang | Allen |
| 2 | Alice | Bob |
+----------+----------+-----------+
Address表:
+-----------+----------+---------------+------------+
| addressId | personId | city | state |
+-----------+----------+---------------+------------+
| 1 | 2 | New York City | New York |
| 2 | 3 | Leetcode | California |
+-----------+----------+---------------+------------+
输出:
+-----------+----------+---------------+----------+
| firstName | lastName | city | state |
+-----------+----------+---------------+----------+
| Allen | Wang | Null | Null |
| Bob | Alice | New York City | New York |
+-----------+----------+---------------+----------+
解释:
地址表中没有 personId = 1 的地址,所以它们的城市和州返回 null.
addressId = 1 包含了 personId = 2 的地址信息.
- 数据库
coding
# Write your MySQL query statement below
select p.firstName, p.lastName, a.city, a.state
from Person p
left join Address a
on p.personId = a.personId
边栏推荐
- Analysis of the principle and implementation of waterfall flow layout
- 链表实现及任务调度
- 那些破釜沉舟入局Web3.0的互联网精英都怎么样了?
- 2. (1) Chained storage of stack, operation of chain stack (illustration, comment, code)
- 【Go语言刷题篇】Go完结篇函数、结构体、接口、错误入门学习
- 基于交替迭代法的交直流混合系统潮流计算matlab程序iEEE9节点系统算例
- 金融租赁业务
- 2022.7.29 数组
- DirectExchange交换机简单入门demo
- bcos简介及自序
猜你喜欢
MySql的安装配置超详细教程与简单的建库建表方法
03-SDRAM: Write operation (burst)
2022.07.12_每日一题
Difficulty comparison between high concurrency and multithreading (easy to confuse)
【微服务】Nacos集群搭建以及加载文件配置
那些破釜沉舟入局Web3.0的互联网精英都怎么样了?
解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?
R——避免使用 col=0
Zero-Shot Learning & Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning
【Go报错】go go.mod file not found in current directory or any parent directory 错误解决
随机推荐
【面试:并发篇37:多线程:线程池】自定义线程池
2022.07.14_每日一题
文件 - 05 下载文件:根据文件Id下载文件
codec2 BlockPool:unreadable libraries
SQL Server Datetime2数据类型
【第四章】详解Feign的实现原理
2022.07.18_每日一题
opencv、pil和from torchvision.transforms的Resize, Compose, ToTensor, Normalize等差别
文件 - 03 下载文件:根据文件id获取下载链接
强化学习科研知识必备(数据库、期刊、会议、牛人)
Log4net 思维导图
[PSQL] SQL基础教程读书笔记(Chapter1-4)
英语翻译软件-批量自动免费翻译软件支持三方接口翻译
把 VS Code 当游戏机
知识、创新、回报。
熟悉而陌生的新朋友——IAsyncDisposable
【微服务】(十六)—— 分布式事务Seata
Zotero | Zotero translator插件更新 | 解决百度学术文献无法获取问题
How to use repeating-linear-gradient
在 ASP.NET Core 应用程序启动时运行代码的 3 种方法