View Single Post
Old 05-26-2006, 11:09 AM   #6 (permalink)
leftwingx
Upright
 
Location: Calgary, AB
I can only comment based on a SQL Server background but you should be able to do it if you can a) Create a temp table or memory table (easiest) or b) use a cursor. This is necessary to create the sub selects and their respective ID's. Then you can use something like this to link your sub queries together (note: @dates is either a temporary table built using your data table and either ):

SELECT TOP 1
d1,
d2,
d1 - d2 [difference]
FROM (SELECT [ID = AUTONUMBER],Date1 [d1] FROM @dates WHERE Date1 NOT IN (SELECT MIN(Date1) FROM @dates)) t1
INNER JOIN (SELECT [ID = AUTONUMBER],Date1 [d2] FROM @dates WHERE Date1 NOT IN (SELECT MAX(Date1) FROM @dates)) t2
ON t1.ID = t2.ID
WHERE d1 - d2 > 30
ORDER BY d1 DESC

So where I wrote [ID = AUTONUMBER] this is an ID that is generated via cursor or as an auto-generated field if you use a temp table. I used this just to illustrate the basic structure of the query not knowing what your capabilities are with your software platform.
__________________
Happiness is just a roughing penalty away.
leftwingx is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73