mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-13 19:31:42 +08:00
add leetcode problem-cn part6
This commit is contained in:
69
算法题(国内版)/problem (Chinese)/组合两个表 [combine-two-tables].html
Normal file
69
算法题(国内版)/problem (Chinese)/组合两个表 [combine-two-tables].html
Normal file
@@ -0,0 +1,69 @@
|
||||
<p>表: <code>Person</code></p>
|
||||
|
||||
<pre>
|
||||
+-------------+---------+
|
||||
| 列名 | 类型 |
|
||||
+-------------+---------+
|
||||
| PersonId | int |
|
||||
| FirstName | varchar |
|
||||
| LastName | varchar |
|
||||
+-------------+---------+
|
||||
personId是该表的主键列。
|
||||
该表包含一些人的ID和他们的姓和名的信息。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>表: <code>Address</code></p>
|
||||
|
||||
<pre>
|
||||
+-------------+---------+
|
||||
| 列名 | 类型 |
|
||||
+-------------+---------+
|
||||
| AddressId | int |
|
||||
| PersonId | int |
|
||||
| City | varchar |
|
||||
| State | varchar |
|
||||
+-------------+---------+
|
||||
addressId是该表的主键列。
|
||||
该表的每一行都包含一个ID = PersonId的人的城市和州的信息。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>编写一个SQL查询来报告 <code>Person</code> 表中每个人的姓、名、城市和状态。如果 <code>personId</code> 的地址不在 <code>Address</code> 表中,则报告为空 <code>null</code> 。</p>
|
||||
|
||||
<p>以 <strong>任意顺序</strong> 返回结果表。</p>
|
||||
|
||||
<p>查询结果格式如下所示。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>
|
||||
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 |
|
||||
+-----------+----------+---------------+------------+
|
||||
<strong>输出:</strong>
|
||||
+-----------+----------+---------------+----------+
|
||||
| firstName | lastName | city | state |
|
||||
+-----------+----------+---------------+----------+
|
||||
| Allen | Wang | Null | Null |
|
||||
| Bob | Alice | New York City | New York |
|
||||
+-----------+----------+---------------+----------+
|
||||
<strong>解释:</strong>
|
||||
地址表中没有 personId = 1 的地址,所以它们的城市和州返回null。
|
||||
addressId = 1 包含了 personId = 2 的地址信息。</pre>
|
Reference in New Issue
Block a user