OT: SQL query puzzler

OT: SQL query puzzler

Old forum URL: forums.lhotka.net/forums/t/133.aspx


Mark posted on Thursday, May 18, 2006

It's late and my brain isn't functioning very well.  :-) I have data in a table that looks like this (excuse the formatting)...

Inv#,Date,CumCycles
1,1/1/2006,500
1,1/5/2006,750
1,1/13/2006,900
2,1/1/2006,25
2,1/5/2006,100
2,1/13/2006,250

I need to be able to run a query that calculates the net cycle count between a date and its prior date for all inventory numbers.  For example, let's use 1/5/2006 as the base date.  Inv #1 would net 250 cycles (750 on 1/5 minus 500 on 1/1) and inv #2 would net 75 cycles.

It seems to me that I've done this in the past (possibly via correlated subquery?) - just can't remember the exact syntax at the moment. 

Ideas?

Mark replied on Thursday, May 18, 2006

Disregard - finally got it straightened out.  Just needed a jolt of caffeine.  :-)

Copyright (c) Marimer LLC