当前位置:网站首页>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
边栏推荐
- 【Go报错】go go.mod file not found in current directory or any parent directory 错误解决
- 2022.07.26_每日一题
- 文件 - 04 下载文件: 根据文件下载链接下载文件
- 【并发编程】ReentrantLock的lock()方法源码分析
- Core Tower Electronics won the championship in the Wuhu Division of the 11th China Innovation and Entrepreneurship Competition
- Zabbix6.2惊喜发布!特别优化中大型环境部署的性能!
- 第十六章:构建n(5,7)阶素数幻方
- 第9章 异常try...except...else...finally
- Obtaining server and client information
- 安装gstreamer开发依赖库到项目sysroot目录
猜你喜欢
随机推荐
【Go语言入门】一文搞懂Go语言的最新依赖管理:go mod的使用
Redux state management
【面试:并发篇37:多线程:线程池】自定义线程池
SQLite数据库连接字符串
【并发编程】ReentrantLock的lock()方法源码分析
Gradle剔除依赖演示
2.(1)栈的链式存储、链栈的操作(图解、注释、代码)
Leetcode952. 按公因数计算最大组件大小
【解决】mysql本地计算机上的MySQL服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止
04-SDRAM:读操作(突发)
codec2 BlockPool:unreadable libraries
【微服务】(十六)—— 分布式事务Seata
安装gstreamer开发依赖库到项目sysroot目录
DAY18:XSS 漏洞
2022.07.12_每日一题
Chapter 16: Constructing the Magic Square for Prime Numbers of Order n(5,7)
LeetCode brush # 376 # Medium - swing sequence
One of the small practical projects - food alliance ordering system
【第四章】详解Feign的实现原理
什么是半波整流器?半波整流器的使用方法









