Hi,
I have a current project which is causing me grief and need help please.
I have a massive list of vehicle maintenance records containing multiple entries against registration numbers and what I need to do is find the latest odometer reading for each Reg. I have written the following query so far which works to a point. However, if a incorrect odometer reading has been entered, say 1000000 miles then I would need the 2nd highest value which would probably be correct. Is there any way of doing this?
Select distinct j.reg_no
,j.work_complete_2
,j.odometer
from vm_001_hdr j
select
reg_no,
max(odometer) as 'latestodo'
from
vm_001_hdr
group by
reg_no
)
tm on j.reg_no = tm.reg_no and j.odometer = tm.latestodo
where j.odometer > '1'
I have a current project which is causing me grief and need help please.
I have a massive list of vehicle maintenance records containing multiple entries against registration numbers and what I need to do is find the latest odometer reading for each Reg. I have written the following query so far which works to a point. However, if a incorrect odometer reading has been entered, say 1000000 miles then I would need the 2nd highest value which would probably be correct. Is there any way of doing this?
Select distinct j.reg_no
,j.work_complete_2
,j.odometer
from vm_001_hdr j
inner join (select
reg_no,
max(odometer) as 'latestodo'
from
vm_001_hdr
group by
reg_no
)
tm on j.reg_no = tm.reg_no and j.odometer = tm.latestodo
where j.odometer > '1'