SELECT client, rate, startdate, enddate, lag(rate) over client_window as pre_rate, lag(startdate) over client_window as pre_startdate, lag(enddate) over client_window as pre_enddate FROM the_table WINDOW client_window as (partition by client order by startdate) ORDER BY client, stardate;
This assumes that enddate is always greater than startdate from the same line and that enddate is greater than the next start
a_horse_with_no_name
source share