当前位置:网站首页>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
边栏推荐
- 科普 | “大姨太”ETH 和 “小姨太”ETC的爱恨情仇
- LeetCode刷题——摆动序列#376#Medium
- 《白帽子说Web安全》思维导图
- HighTec 的安装与配置
- Foreign trade website optimization - foreign trade website optimization tutorial - foreign trade website optimization software
- Log4net 思维导图
- 嵌入式系统驱动初级【2】——内核模块下_参数和依赖
- 完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?
- 芯塔电子斩获第十一届中国双创大赛芜湖赛区桂冠
- bcos简介及自序
猜你喜欢
测试 思维导图
零样本学习&Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning
关于求反三角函数的三角函数值
Leetcode952. 按公因数计算最大组件大小
【Go报错】go go.mod file not found in current directory or any parent directory 错误解决
基金投顾业务
Analysis of the implementation principle and detailed knowledge of v-model syntactic sugar and how to make the components you develop support v-model
科普 | “大姨太”ETH 和 “小姨太”ETC的爱恨情仇
LeetCode brush # 376 # Medium - swing sequence
【微服务】(十六)—— 分布式事务Seata
随机推荐
【Go语言入门教程】Go语言简介
基于交替迭代法的交直流混合系统潮流计算matlab程序iEEE9节点系统算例
nohup原理
2022.07.29_每日一题
自动翻译软件-批量批量自动翻译软件推荐
04-SDRAM:读操作(突发)
深度学习通信领域相关经典论文、数据集整理分享
从入门到一位合格的爬虫师,这几点很重要
强化学习科研知识必备(数据库、期刊、会议、牛人)
postgresql源码学习(33)—— 事务日志⑨ - 从insert记录看日志写入整体流程
Foreign trade website optimization - foreign trade website optimization tutorial - foreign trade website optimization software
Run the NPM will pop up to ask "how are you going to open this file?"
事务的四大特性
PCB抄板
Zabbix6.2惊喜发布!特别优化中大型环境部署的性能!
【TA-霜狼_may-《百人计划》】美术2.3 硬表面基础
Zero-Shot Learning & Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning
庐山谣寄卢侍御虚舟
2022.07.18_每日一题
2022.07.12_每日一题