当前位置:网站首页>Database daily question --- day 22: last login
Database daily question --- day 22: last login
2022-07-28 00:54: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 .
SQL20202020Two 、 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
20202020maxFour 、 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



边栏推荐
- Jerry's prompt sound processing when switching devices [chapter]
- 多线程及多线程程序的编写
- Set data constructor
- Read cmake in one article
- 阿里二面:为什么要分库分表?
- What are the namespaces and function overloads of + and @ in front of MATLAB folder
- scrollview、tableView嵌套解决方案
- KMP review + AC automata Prequel
- Network device hard core technology insider firewall and security gateway (10)
- startUMl
猜你喜欢

Basic operations of MySQL database (2) --- Based on data table
![[BuildRelease Management]Parabuild](/img/80/11c2b539c217ecd6ba55668d3e71e9.png)
[BuildRelease Management]Parabuild

分支和循环语句题目练习

递归求解迷宫问题

激活最大化

Jmeter 如何解决乱码问题?

From the second floor to the third floor

红队大杀器 Behinder_v4.0(冰蝎4.0)
![[must read for new products] valuation analysis of Meishi technology, distributed audio-visual products and Solutions](/img/40/bf3e992e363dbd6600805775058310.jpg)
[must read for new products] valuation analysis of Meishi technology, distributed audio-visual products and Solutions

Buildforge materials
随机推荐
一周年创作纪念日,冲吧少年郎
Arm发布全新A78/G78/N78内核!还有支持自定义的Cortex-X系列CPU
Interesting Huffman tree
融云 IM & RTC 能力上新盘点
自动推理的逻辑09–自动定理证明
Syntaxerror resolved: positive argument follows keyword argument
leetcode:1997. 访问完所有房间的第一天【跳跃dp】
网络设备硬核技术内幕 防火墙与安全网关篇 (九) 虚拟化神器 (下)
为华为打造无美系设备的产线,台积电三星能做到吗?
程序员工作中的理性与感性活动及所需的技能素养
R language evaluates the relative importance of the predictive factors (variables, characteristics) of the regression model, scales the predictive variables of the regression model, and then construct
单片机之led、数码管与按键
Jerry's PWM setting and PWM IO selection [chapter]
ASML推出第一代HMI多光束检测机:速度提升600%,适用于5nm及更先进工艺
Data visualization - White Snake 2: black snake robbery (3)
Volkswagen China invested 8billion yuan and became the largest shareholder of GuoXuan high tech
Read cmake in one article
Redis learning and understanding of three special data types
The server is poisoned - the dish is the original sin
Solve maze problem recursively