Ask the Expert

Comparing adjacent rows, part 2

I am trying to create a SELECT statement that will take a date/time field, compare the second record with the first record, select it if the second record's time is greater than the first record's time by 15 minutes or more, then do the same comparison for the next record and its previous record through the entire result set.

    Requires Free Membership to View

Click to return to part 1.

The values returned by analytic functions can not be used in the WHERE, GROUP BY or ORDER BY clauses of the query in which they were computed. Since we want to do just that (use the value returned by LAG in a WHERE clause), we have to compute the value in a sub-query:

This was first published in April 2004

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.