惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - 一叶知秋。

从包含时间属性的对象列表中,筛选出时间≤指定时间参数且最接近该时间参数的那个对象 安装nginx和OpenSSL struts2的<s:if test>标签的注意点 mysql怎么写逻辑比较清晰? 设置idea 代码报错时不弹框显示 Collections.sort多个字段排序 LigerUI 中的 Grid (ligerGrid) 合并单元格 mysql模糊查找数据库使用的字段名 spring RestTemplate忽略证书验证 关于easyExcel解析未添加@ExcelProperty报错问题分析 Nginx的常用命令(启动重启停止等) 解决远程调用三方接口:javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException报错 msyql查询表的索引sql语句 MySQL查看表占用空间大小 js屏蔽回车提交 kettle同步表数据null处理 mysql解表和查看锁表 Windows关闭指定端口命令 Windows 技术篇-防火墙启用时指定外部可访问端口,防火墙开放端口设置
MySql 分组后获取距离时间最近的第一条数据
一叶知秋。 · 2022-09-04 · via 博客园 - 一叶知秋。

按照user_id 分组,取每组中update_time 最大的那一条记录。

本质有两种方法,目前推荐采用第二种

// 低版本5.7以下可以生效
SELECT *
FROM  (select * from tabletable where xxx order by update_time DESC) b 
GROUP BY b.user_id;
// 所有版本均适用
SELECT t.*
FROM (
      SELECT user_id, MAX(update_time) as update_time
      FROM tabletable
      WHERE xxx
      GROUP BY user_id
) r
INNER JOIN tabletable t
ON t.user_id = r.user_id AND t.update_time = r.update_time
GROUP BY t.user_id;