当前位置:网站首页>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
边栏推荐
- 小实战项目之——吃货联盟订餐系统
- 基于交替迭代法的交直流混合系统潮流计算matlab程序iEEE9节点系统算例
- 文件 - 02 上传文件:上传临时文件到服务器
- 服务器和客户端信息的获取
- 2022.07.20_每日一题
- 【编程题】【Scratch三级】2022.03 冬天下雪了
- 2.(1)栈的链式存储、链栈的操作(图解、注释、代码)
- Yu Mr Series 】 【 2022 July 022 - Go Go teaching course of container in the dictionary
- 芯塔电子斩获第十一届中国双创大赛芜湖赛区桂冠
- Detailed explanation of js prototype
猜你喜欢

Zotero | Zotero translator插件更新 | 解决百度学术文献无法获取问题

任务及任务切换

熟悉而陌生的新朋友——IAsyncDisposable

我开发了一个利用 Bun 执行 .ts / .js 文件的 VS Code 插件

外贸网站优化-外贸网站优化教程-外贸网站优化软件

高并发与多线程之间的难点对比(容易混淆)

Automatic translation software - batch batch automatic translation software recommendation

单点登录 思维导图

2022.07.18_每日一题

Analysis of the implementation principle and detailed knowledge of v-model syntactic sugar and how to make the components you develop support v-model
随机推荐
SQL Server Datetime2数据类型
leetcode 406. Queue Reconstruction by Height 根据身高重建队列(中等)
【微服务】Nacos集群搭建以及加载文件配置
2022.07.29_每日一题
Difficulty comparison between high concurrency and multithreading (easy to confuse)
毫米波技术基础
【 TA - frost Wolf _may - "one hundred plan" 】 art 2.3 hard surface
第十七章:回溯探求指定入口的马步遍历,贪心无回溯探求马步遍历,递归探求nxm棋盘带障碍马步遍历
Titanic 预测问题
【编程题】【Scratch三级】2022.03 冬天下雪了
DAY18:XSS 漏洞
2. (1) Chained storage of stack, operation of chain stack (illustration, comment, code)
自动翻译软件-批量批量自动翻译软件推荐
DAY18:Xss 靶场通关手册
Zero-Shot Learning & Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning
R——避免使用 col=0
【并发编程】ReentrantLock的lock()方法源码分析
一文读懂 MongoDB 和 MySQL 的差异
从入门到一位合格的爬虫师,这几点很重要
Leetcode952. 按公因数计算最大组件大小