Forum: comp
Page 438
Subject: SQL query help


  Posted by: RecycledSpinalFluid - Dude [204401122] Thu, Dec 31, 2009, 00:39

Access/SQL is not my strong point, so I'm asking for some help.

In an Access MDB, I have a table (tblHistory) that looks like this:

dDate (a date/time field)
iIdentNumber (integer)
iCount (integer)

Now, what I want to do is make a query that shows the iIdentNumber where the iCount has incremented over a 1 day period (from [date - 1] to [date].

Make sense? I swear I've done this before, but its escaping me now.

Any help is appreciated.
 
1Dr. Doom
      ID: 430271612
      Thu, Dec 31, 2009, 15:27
Assuming iIdentNumber is the key field.

One way might be

select iIdentNumber
from foo t1
join foo t2
where t1.iIdentNumber = t2.iIdentNumber
and t1.dDate = t2.dDate -1
and t1.iCount > t2.iCount
;

Not sure if the syntax is exactly right but the idea should be close.
 
2RecycledSpinalFluid
      Dude
      ID: 204401122
      Thu, Dec 31, 2009, 17:34
Ah! Many thanks. Wasn't thinking JOIN the table to itself. Built it with the Query Wizard in Access after looking at your suggestion and its good to go now (and rather bloated looking)!

Thanks again!