Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    1

    Unanswered: help with a query/function to determine if a field for record A differs from record B

    I need to write a query or function that determines when there is a change in the data for a field between different records. Say for example:

    Record_ID Field
    1 Val1
    2 Val1
    3 Val1
    4 Val2
    5 Val2
    6 Val1

    I would want to return that records 4 and 6 had different values than the previous records. These values will be variable, I cannot define them explicitly. Anybody done something like this?

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Wink Lag

    Try the LAG analytical function.
    .
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >I would want to return that records 4 and 6 had different values than the previous records
    Rows in a table have NO inherent order!
    Rows in a table are like balls in a basket.
    How do you identify the "first" ball or the "next" ball in the basket?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Talking Analytical or not analytical, that is the question...

    Quote Originally Posted by anacedent
    >I would want to return that records 4 and 6 had different values than the previous records
    Rows in a table have NO inherent order!
    Rows in a table are like balls in a basket.
    How do you identify the "first" ball or the "next" ball in the basket?
    Using the LAG function with LAG(...) OVER (ORDER BY ...)
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •