mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-13 19:31:42 +08:00
add leetcode problem-cn part4
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<p>表: <code>Logins</code></p>
|
||||
|
||||
<pre>
|
||||
+----------------+----------+
|
||||
| 列名 | 类型 |
|
||||
+----------------+----------+
|
||||
| user_id | int |
|
||||
| time_stamp | datetime |
|
||||
+----------------+----------+
|
||||
(user_id, time_stamp) 是这个表的主键。
|
||||
每一行包含的信息是user_id 这个用户的登录时间。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>编写一个 SQL 查询,该查询可以获取在 <code>2020</code> 年登录过的所有用户的本年度 <strong>最后一次 </strong>登录时间。结果集 <strong>不</strong> 包含 <code>2020</code> 年没有登录过的用户。</p>
|
||||
|
||||
<p>返回的结果集可以按 <strong>任意顺序 </strong>排列。</p>
|
||||
|
||||
<p>查询结果格式如下例。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>
|
||||
Logins 表:
|
||||
+---------+---------------------+
|
||||
| user_id | time_stamp |
|
||||
+---------+---------------------+
|
||||
| 6 | 2020-06-30 15:06:07 |
|
||||
| 6 | 2021-04-21 14:06:06 |
|
||||
| 6 | 2019-03-07 00:18:15 |
|
||||
| 8 | 2020-02-01 05:10:53 |
|
||||
| 8 | 2020-12-30 00:46:50 |
|
||||
| 2 | 2020-01-16 02:49:50 |
|
||||
| 2 | 2019-08-25 07:59:08 |
|
||||
| 14 | 2019-07-14 09:00:00 |
|
||||
| 14 | 2021-01-06 11:59:59 |
|
||||
+---------+---------------------+
|
||||
<strong>输出:</strong>
|
||||
+---------+---------------------+
|
||||
| user_id | last_stamp |
|
||||
+---------+---------------------+
|
||||
| 6 | 2020-06-30 15:06:07 |
|
||||
| 8 | 2020-12-30 00:46:50 |
|
||||
| 2 | 2020-01-16 02:49:50 |
|
||||
+---------+---------------------+
|
||||
<strong>解释:</strong>
|
||||
6号用户登录了3次,但是在2020年仅有一次,所以结果集应包含此次登录。
|
||||
8号用户在2020年登录了2次,一次在2月,一次在12月,所以,结果集应该包含12月的这次登录。
|
||||
2号用户登录了2次,但是在2020年仅有一次,所以结果集应包含此次登录。
|
||||
14号用户在2020年没有登录,所以结果集不应包含。</pre>
|
Reference in New Issue
Block a user