当前位置:网站首页>Database daily question --- day 22: last login
Database daily question --- day 22: last login
2022-07-07 23:00:00 【InfoQ】
One 、 Problem description
Logins
+----------------+----------+
| Name | type |
+----------------+----------+
| user_id | int |
| time_stamp | datetime |
+----------------+----------+
(user_id, time_stamp) It's the primary key of this table .
The information contained in each line is user_id The login time of this user .
SQL
2020
2020
Two 、 Subject requirements
Examples
Input :
Logins surface :
+---------+---------------------+
| 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 |
+---------+---------------------+
Output :
+---------+---------------------+
| 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 |
+---------+---------------------+
explain :
6 User number is logged in 3 Time , But in 2020 Only once a year , Therefore, the result set should include this login .
8 User number is 2020 Logged in in 2 Time , Once in 2 month , Once in 12 month , therefore , The result set should contain 12 This login in June .
2 User number is logged in 2 Time , But in 2020 Only once a year , Therefore, the result set should include this login .
14 User number is 2020 I didn't log in in , Therefore, the result set should not contain .
Investigate
1. Aggregate functions
2. It is recommended to use time 10~25min
3、 ... and 、 Problem analysis
2020
2020
max
Four 、 coded
select user_id, max(time_stamp) as 'last_stamp'
from Logins
where year(time_stamp)=2020
group by user_id
5、 ... and 、 test result
边栏推荐
- Debezium series: binlogreader for source code reading
- Line test - graphic reasoning - 4 - alphabetic class
- LeetCode206. Reverse linked list [double pointer and recursion]
- “拧巴”的早教行业:万亿市场,难出巨头
- Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~
- LeetCode203. Remove linked list elements
- 不夸张地说,这是我见过最通俗易懂的,pytest入门基础教程
- How to choose the appropriate automated testing tools?
- Leetcode94. Middle order traversal of binary trees
- Explain in detail the communication mode between arm A7 and risc-v e907 on Quanzhi v853
猜你喜欢
Line test - graphic reasoning - 1 - Chinese character class
Microbial Health Network, How to restore Microbial Communities
What is fake sharing after filling the previous hole?
LeetCode203. Remove linked list elements
PCL . VTK files and Mutual conversion of PCD
CTF exercise
Line test graph reasoning graph group class
Why is network i/o blocked?
今日创见|企业促进创新的5大关键要素
Microbial health network, how to restore microbial communities
随机推荐
消息队列与快递柜之间妙不可言的关系
Why is network i/o blocked?
Line test - graphic reasoning -7- different graphic classes
Ligne - raisonnement graphique - 4 - classe de lettres
Micro service remote debug, nocalhost + rainbow micro service development second bullet
一次搞明白 Session、Cookie、Token,面试问题全稿定
微生物健康网,如何恢复微生物群落
行测-图形推理-3-对称图形类
Yarn cannot view the historical task log of yarn after enabling ACL user authentication. Solution
Install mxnet GPU version
Debezium系列之:引入对 LATERAL 运算符的支持
Debezium series: introducing support for the final operator
PHP records the pitfalls encountered in the complete docking of Tencent cloud live broadcast and im live group chat
Loki, the "open source star picking program", realizes the efficient management of harbor logs
Leetcode19. Delete the penultimate node of the linked list [double pointer]
知识点滴 - PCB制造工艺流程
Cause analysis and solution of too laggy page of [test interview questions]
Take full control! Create a "leading cockpit" for smart city construction
Visual studio 2019 installation
7-18 simple simulation of banking business queue