× 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.



Say it isn't so, Roger!!! Retire? Nooooooooooooo!!

:)

On 3/9/2023 8:05 PM, Roger Harman wrote:
I soooo wanted to use LAG() and LEAD()for a couple of tasks. Sadly, we were on 7.2 and I retired before they upgraded - if they even have now.

Dang....


Roger Harman
COMMON Certified Application Developer - ILE RPG on IBM i on Power

-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Vern Hamberg via MIDRANGE-L
Sent: Thursday, March 9, 2023 5:41 PM
To: midrange-l@xxxxxxxxxxxxxxxxxx
Cc: Vern Hamberg <vhamberg@xxxxxxxxxxxxxxx>
Subject: Re: Does SQL by chance currently support row look-behind and look-ahead?

I googled for "join row with previous row sql" and got this hit -
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F710212%2Fis-there-a-way-to-access-the-previous-row-value-in-a-select-statement&data=05%7C01%7C%7C763aff32a4ce40a7d95208db21087d16%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638140092558361233%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=SgXNLM%2BL0dHelv8D6aO%2FhosUZn4ilcvvu4dHpAbhVPI%3D&reserved=0

It mentions lag and lead functions - these are OLAP functions - I
wondered if they exist on the i. And they do -

LAG or LEAD Returns an expression value computed using rows prior to or
following the current row.

These seem to have been added in 7.3 - yes, it is not in 7.2

This looks like just the thing - you do need something that sorts the
results - a windowing thing - it's explained in the manual,
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.ibm.com%2Fdocs%2Fen%2Fssw_ibm_i_73%2Fpdf%2Frbafzpdf.pdf&data=05%7C01%7C%7C763aff32a4ce40a7d95208db21087d16%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638140092558361233%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=yjgcdMuCols0tcQHpA8jo%2B8s5u8CBtJgHYMxi1%2BaEzM%3D&reserved=0, around page 184.

Enjoy!!
Vern

On 3/9/2023 6:36 PM, Javier Sanchez wrote:
I have always liked the idea of doing something with the previous and/or
the next-look-ahead row while you work with the current row. I suspect
that exists. But not with external coding but with some kind of say:

select col1, col2 + PREVIOUS_ROW(col1) from sometable where
somecondition=true/false; // whatever

There may also be a kind of NEXT_ROW(col2) thing.

This is of course a meta-statement of the idea.

You may say I can write a UDF that returns the previous row col2 value, but
it would be very difficult because of the nature of your table and your
logic.

It would be nice that this be an intrinsic DB2 functionality. Do we have
that already?

Please your comments.

TIA.

Javier.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.