1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-12 02:41:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

存量题库数据更新

This commit is contained in:
2023-12-09 18:42:21 +08:00
parent a788808cd7
commit c198538f10
10843 changed files with 288489 additions and 248355 deletions

View File

@@ -1,4 +1,4 @@
<p>部门&nbsp;<code>Department</code></p>
<p>&nbsp;<code>Department</code></p>
<pre>
+---------------+---------+
@@ -8,19 +8,26 @@
| revenue | int |
| month | varchar |
+---------------+---------+
(id, month) 是表的联合主键。
在 SQL 中,(id, month) 是表的联合主键。
这个表格有关于每个部门每月收入的信息。
月份month可以取下列值 [&quot;Jan&quot;,&quot;Feb&quot;,&quot;Mar&quot;,&quot;Apr&quot;,&quot;May&quot;,&quot;Jun&quot;,&quot;Jul&quot;,&quot;Aug&quot;,&quot;Sep&quot;,&quot;Oct&quot;,&quot;Nov&quot;,&quot;Dec&quot;]。
月份month可以取下列值 ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]。
</pre>
<p>&nbsp;</p>
<p>编写一个 SQL 查询来重新格式化表,使得新的表中有一个部门 id 列和一些对应&nbsp;<strong>每个月 </strong>的收入revenue列。</p>
<p>重新格式化表,使得&nbsp;<strong>每个月&nbsp;</strong>都有一个部门 id 列和一个收入列。</p>
<p>查询结果格式如下面的示例所示:</p>
<p><strong>任意顺序</strong> 返回结果表。</p>
<p>结果格式如以下示例所示。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
Department 表:
<b>输入:</b>
Department table:
+------+---------+-------+
| id | revenue | month |
+------+---------+-------+
@@ -30,8 +37,7 @@ Department 表:
| 1 | 7000 | Feb |
| 1 | 6000 | Mar |
+------+---------+-------+
查询得到的结果表:
<b>输出:</b>
+------+-------------+-------------+-------------+-----+-------------+
| id | Jan_Revenue | Feb_Revenue | Mar_Revenue | ... | Dec_Revenue |
+------+-------------+-------------+-------------+-----+-------------+
@@ -39,6 +45,5 @@ Department 表:
| 2 | 9000 | null | null | ... | null |
| 3 | null | 10000 | null | ... | null |
+------+-------------+-------------+-------------+-----+-------------+
注意,结果表有 13 列 (1个部门 id 列 + 12个月份的收入列)。
</pre>
<b>解释:</b>四月到十二月的收入为空。
注意,结果表有 13 列1 列用于部门 ID其余 12 列用于各个月份)。</pre>