Query that filters based on consecutive dates

  • Hi,

    I am trying to build a query which would filter based on the DATEDIFF between a date field in one record and the same date field in the previous record within an appropriate Grouping and Sort.

    I am sure that there is a neat way for doing it, but I just don't know how.

     

     

    Thanks,   J

     

     

  • Can you supply a bit more detail?

  • Let us say that we have a table with 3 fields fields: EventLog EventDescription and EventDate.

     

    I would like to find all the events which the previous event was more than 10 days before:

     

    EventDate(Record x) - EventDate(Record x-1) > 10

  • try this

    select * from eventtable a

     where exists(select * from eventtable b

     where a.eventlog = b.eventlog

     and datediff(dd, b.eventdate, a.eventdate) > 10)

    -- and a.eventdate >= ''

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply