需要SQL查询来查找表中每个父项的最后/最新子项 [英] Need a SQL Query to find Last/Latest Child for Each Parent item in a table

查看:102
本文介绍了需要SQL查询来查找表中每个父项的最后/最新子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我是Excel VBA程序员,我在SQL和Access方面不太好。任何人都可以通过以下方案帮助我


要求是获取表格中每辆车的最新服务日期。该表如下所示:

Hi,

I am a Excel VBA programmer, I am not so good in SQL and Access. can any one help me with the below scenario

The requirement is to get the latest serviced date for each car in the table. The table looks like this:

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号

推荐答案

问题的含义很清楚,但是你我们遗漏了一个重要的细节,这是什么在你的桌子中唯一标识一个单独的记录?它显然不是那些显示的单个字段,因此可能是一些字段合在一起或不包括单独的字段。请澄清,以便有人可以帮助您。
The meaning of the question is quite clear, but you''ve left out one important detail, which is what identifies an individual record uniquely in your table? It''s clearly not a single field of those shown, so it''s probably a number of fields taken together or a separate field not included. Please clarify in order that someone can help you.


如果我对您的示例数据感到困惑,我很抱歉,唯一字段是SrvcID。逻辑是,汽车CAB123有三条记录,OWN321有四条记录,但是我想获取每张车在表中写的最新记录。


我必须使用SrvcID号码来查找汽车的最新记录,这是汽车最大的SrvcID,也是最新的SrvcID。同样,我必须为表中的每辆车获得最大的SrvcID。
I am sorry if i have confused you with that sample data, The Unique field is the SrvcID. The logic is that, the car CAB123 has got three records and OWN321 has four in the table, however i want to fetch the one latest record written in the table for each car.

I must use SrvcID numbers to find out the latest record for a car, that is the largest SrvcID for a car would be the latest SrvcID for the same. Similarly I have to get largest SrvcIDs for each car in the table.


NarenKeer:

Unique字段是SrvcID。
NarenKeer:
The Unique field is the SrvcID.



你确定吗?它们似乎与日期有关,所以多个车辆可以具有相同的[SrvcID]值?

Are you sure. They seem to be date related so surely multiple vehicles could have the same [SrvcID] value?


这篇关于需要SQL查询来查找表中每个父项的最后/最新子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆