Hello....
In some (sql)languages there is a possibility to compare a field from row 1 with the same field in row 2.
P.E.
here is the query:
ref cust purch_date
123 1001 2005-01-03
123 1001 2005-04-01
123 1004 2005-02-01
172 1043 2005-02-28
172 1043 2005-03-20
172 1043 2005-03-31
195 1047 2005-01-13
What I'd like to have is:
the output:
ref|cust|purch_date|ref_from_prev_row|cust_from_prev_row
123 1001 2005-01-03 Null Null
123 1001 2005-04-01 123 1001
123 1004 2005-02-01 123 1001
172 1043 2005-02-28 123 1004
172 1043 2005-03-20 172 1043
172 1043 2005-03-31 172 1043
195 1047 2005-01-13 172 1043
maybe there is an function like prior or next.
select ref, prior(ref) as ref_from_prev_row from sell ....
Can you help me?
Henky
In some (sql)languages there is a possibility to compare a field from row 1 with the same field in row 2.
P.E.
here is the query:
Code:
SELECT ref, cust, purch_date
FROM sell
ORDER BY ref, cust, purch_date
GO
123 1001 2005-01-03
123 1001 2005-04-01
123 1004 2005-02-01
172 1043 2005-02-28
172 1043 2005-03-20
172 1043 2005-03-31
195 1047 2005-01-13
What I'd like to have is:
Code:
SELECT ref, cust, purch_date, ref_from_prev_row, cust_from_prev_row
FROM sell
ORDER BY ref, cust, purch_date
GO
the output:
ref|cust|purch_date|ref_from_prev_row|cust_from_prev_row
123 1001 2005-01-03 Null Null
123 1001 2005-04-01 123 1001
123 1004 2005-02-01 123 1001
172 1043 2005-02-28 123 1004
172 1043 2005-03-20 172 1043
172 1043 2005-03-31 172 1043
195 1047 2005-01-13 172 1043
maybe there is an function like prior or next.
select ref, prior(ref) as ref_from_prev_row from sell ....
Can you help me?
Henky