Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3969164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:55:51+00:00 2026-05-20T03:55:51+00:00

To keep it simple, my question is similar to THIS QUESTION, PART 2 ,

  • 0

To keep it simple, my question is similar to THIS QUESTION, PART 2, only problem is, I am not running Oracle and thus can not use the rownumbers.

For those who need more information and examples:

I have a table

  contractId date          value    
  1          09/02/2011     A         
  1          13/02/2011     C          
  2          02/02/2011     D   
  2          08/02/2011     A  
  2          12/02/2011     C  
  3          22/01/2011     C  
  3          30/01/2011     B  
  3          12/02/2011     D    
  3          21/01/2011     A

EDIT: added another line for ContractID. Since I had some code myself, but that would display the following:

  contractId date          value    value_old
  1          09/02/2011     A                  
  2          08/02/2011     A         D
  3          30/01/2011     B         C    
  3          30/01/2011     B         A 

But that is not what I want ! The result should still be as below!

Now I want to select the last record before a given date and compare that with the previous value.
Suppose the ‘given date’ is 11/02/2011 in this example, the output should be like this:

  contractId date          value    value_old
  1          09/02/2011     A                  
  2          08/02/2011     A         D
  3          30/01/2011     B         C    

I do have the query to select the last record before the given date. That is the easy part. But to select the last record before that, I am lost…

I really hope I can get some help here, have been breaking my head over this for days and looking for answers on the web and stackoverflow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:55:52+00:00Added an answer on May 20, 2026 at 3:55 am

    One possibility:

    SELECT a.contractId, a.Date, a.Value, (SELECT Top 1 b.[Value] 
            FROM tbl b 
            WHERE b.[Date] < a.[Date] And b.ContractID=a.ContractID
            ORDER BY b.[Date] Desc) AS Old_Value
    FROM tbl AS a
    WHERE a.Date IN 
           (SELECT TOP 1 b.Date 
            FROM tbl b 
            WHERE b.ContractID=a.ContractID
            AND b.Date < #2011/02/11#
            ORDER BY b.date DESC)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've had a similar question but the answer did not entirely fix my problem.
This is probably not a simple question so I am not looking for a
Note: This is not a question whether I should use list or deque. It's
This question is very similar to that posed here . My problem is that
I want to keep the class simple and not defined a constructor so i
I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I keep running across this loading image http://georgia.ubuntuforums.com/images/misc/lightbox_progress.gif which seems to have entered into
Another simple question from silly old me. We keep hearing big numbers being thrown
This is probably a very simple question to an experienced person with UNIX however
This is probably a very simple question to an experienced person with UNIX however

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.