RRinTetons
IS-IT--Management
I'd hate to attract the scorn of all right thinking SQL folks by resorting to a cursor, but I don't see anyway to avoid it. Any ideas?
Given this data:
Season,CustomerID,TranID,TranLine,Product,Quantity
2008-2009,00111,111111,1,1011,1
2008-2009,00112,111120,1,1011,1
2008-2009,00115,111125,1,1011,1
2008-2009,00115,111125,1,1011,-1
2008-2009,00115,111128,1,1013,1
2009-2010,00111,111199,1,1011,1
2009-2010,00111,111199,1,1011,-1
2009-2010,00111,111200,1,1013,1
2009-2010,00133,111221,1,1011,1
I want to return only the last row for a customer for a given season; the product the customer had as of his/her last transaction for a given season. So, in the case above, I should get:
2008-2009,00111,111111,1,1011,1
2008-2009,00112,111120,1,1011,1
2008-2009,00115,111128,1,1013,1
2009-2010,00111,111200,1,1013,1
2009-2010,00133,111221,1,1011,1
The actual data has more columns and about 150,000 rows.
Easy enough to do with a bunch of variables and walking through it with a cursor. Any better approach?
-
Richard Ray
Jackson Hole Mountain Resort
Given this data:
Season,CustomerID,TranID,TranLine,Product,Quantity
2008-2009,00111,111111,1,1011,1
2008-2009,00112,111120,1,1011,1
2008-2009,00115,111125,1,1011,1
2008-2009,00115,111125,1,1011,-1
2008-2009,00115,111128,1,1013,1
2009-2010,00111,111199,1,1011,1
2009-2010,00111,111199,1,1011,-1
2009-2010,00111,111200,1,1013,1
2009-2010,00133,111221,1,1011,1
I want to return only the last row for a customer for a given season; the product the customer had as of his/her last transaction for a given season. So, in the case above, I should get:
2008-2009,00111,111111,1,1011,1
2008-2009,00112,111120,1,1011,1
2008-2009,00115,111128,1,1013,1
2009-2010,00111,111200,1,1013,1
2009-2010,00133,111221,1,1011,1
The actual data has more columns and about 150,000 rows.
Easy enough to do with a bunch of variables and walking through it with a cursor. Any better approach?
-
Richard Ray
Jackson Hole Mountain Resort