Oliver Elphick <olly@xxxxxxxxxx> writes: > I tried to do this: > SELECT p.company, p.start, p.yearend, p.idnum, > s.pdno, s.pdend, > CASE WHEN nth_value(s.pdend,(row_number() OVER w)::INTEGER -1) OVER w IS NULL > THEN p.start > ELSE nth_value(s.pdend,(row_number() OVER w)::INTEGER -1) + '1 day'::INTERVAL Um, don't you just want lead() or lag()? regards, tom lane -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general