Not sure if it is exactly what you are looking for:
1. Build a rank with level break on the week (in my example WEEK according
the ISO guidelines) and based on the descending date. In this way the last
date (in the week) gets rank 1.
2. Select all rows Rank 1 to 3
With x as (Select Dense_Rank Over(Partition By
VarChar_Format(Timestamp(YourDate), 'IYYY/IW')
Order By YourDate Desc) as RunWeek,
a.*
From YourTable)
Select * from x
Where runWeek between 1 and 3;
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
-----Ursprüngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im Auftrag von Booth
Martin
Gesendet: Saturday, 27.2 2016 04:43
An: RPG programming on the IBM i / System i
Betreff: RPG Embedded SQL: select latest date in a week
I am going in circles on this. Perhaps its simpler than I am making it.
3 rows are added to a file most days. Lets say, to give a perspective, that
somewhere around 300 days/year there are 3 records added. Never 4, never 2.
Its 3 or none. I want 3 rows for every week of the year, in descending
order, but only the last active day in each week. Normally it is day 7,
sometimes day 6, rarely day 5.
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
As an Amazon Associate we earn from qualifying purchases.