× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Oops sorry - you probably want DESC on the order by on TYPE and DATE

e.g

select t1.*, t2.*
from FILE t1
left join lateral (
select t2.* from FILE t2
where t1.id = t2.id
and t2.type < 'REPAIR'
order by id, type DESC, date DESC
fetch first row only) as t2 on 1 = 1
where t1.type = 'REPAIR'

On Tue, 29 Oct 2019 at 14:29, Craig Richards <craig@xxxxxxxxxxxxxxxx> wrote:

Mike,

Looking at your data and keys:

ID TYPE Date Status
21489 RECHECK 20180928 2
21489 REGRADE 20180418 2
21489 REPAIR 20190102 0

Key in file is ID,TYPE,Date

The previous record in ID / TYPE sequence would be 21489 RECHECK.

So - what about this:

select t1.*, t2.*
from FILE t1
left join lateral (
select t2.* from FILE t2
where t1.id = t2.id
and t2.type < 'REPAIR'
order by id, type, date
fetch first row only) as t2 on 1 = 1
where t1.type = 'REPAIR'

t2.* should have your previous values in.

regards,
Craig





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.