当前位置:网站首页>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



边栏推荐
猜你喜欢
Robot autonomous exploration DSVP: code parsing
苹果在iOS 16中通过'虚拟卡'安全功能进一步进军金融领域
Yarn cannot view the historical task log of yarn after enabling ACL user authentication. Solution
C # realizes the communication between Modbus protocol and PLC
今日创见|企业促进创新的5大关键要素
How to choose the appropriate automated testing tools?
新版代挂网站PHP源码+去除授权/支持燃鹅代抽
Leetcode1984. Minimum difference in student scores
行测-图形推理-8-图群类
ASP. Net core introduction V
随机推荐
0-5vac to 4-20mA AC current isolated transmitter / conversion module
Failed to initialize rosdep after installing ROS
Class implementation of linear stack and linear queue (another binary tree pointer version)
Unity technical notes (I) inspector extension
软件测评中心▏自动化测试有哪些基本流程和注意事项?
Debezium系列之:引入对 LATERAL 运算符的支持
QT graphicsview graphical view usage summary with flow chart development case prototype
Select sort (illustration +c code)
Microbial Health Network, How to restore Microbial Communities
筑起云端 “免疫”屏障,让你的数据有备无患
Line test - graphic reasoning -5- one stroke class
微服務遠程Debug,Nocalhost + Rainbond微服務開發第二彈
CTF练习
Debezium series: source code reading snapshot reader
Debezium series: MySQL tombstone event
Unity and webgl love each other
Micro service remote debug, nocalhost + rainbow micro service development second bullet
Line test - graphic reasoning - 1 - Chinese character class
Debezium series: binlogreader for source code reading
How to judge whether the input content is "number"