选择每个ID具有最新日期的数据

编程入门 行业动态 更新时间:2024-10-23 12:25:53
本文介绍了选择每个ID具有最新日期的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在使用Microsoft Access,但我正在努力做自己想做的事情.我有这张桌子A:

I am currently working on Microsoft Access an I am struggling to do what I want. I have this table A:

Table A id title name date 123 azer dfgd 1 123 afg qsd 5 123 arr poi 7 123 aur qhg 3 456 aoe aer 3 456 iuy zer 4

我想获取每个ID具有最新日期(最高编号)的ID,标题和名称列

And I would like to get the columns id,title and name that have the latest date (highest number) for each id

在该示例中,查询将给出

With that example, the query would give

id title name date 123 arr poi 7 456 iuy zer 4

希望您能为我提供帮助.

I hope you'll be able to help me.

提前谢谢!

推荐答案

我建议使用相关子查询:

I would recommend a correlated subquery:

select a.* from a where a.date = (select max(a2.date) from a as a2 where a2.id = a.id);

为了提高性能,您需要在 a(id,date)上建立索引.

For performance, you want an index on a(id, date).

更多推荐

选择每个ID具有最新日期的数据

本文发布于:2023-10-14 21:56:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492328.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   数据   最新   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!