Results 1 to 3 of 3
  1. #1
    wijo85 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2017
    Posts
    3

    INNER JOIN same table ON closest earlier date

    table: t_instrument_price



    InstrumentID
    InstrumentPrice
    PriceDate

    example data:
    InstrumentID InstrumentPrice PriceDate
    1 82.03 07/25/2017
    1 82.08 07/24/2017
    1 81.97 07/21/2017
    2 115 07/25/2017
    2 114.5 07/24/2017
    2 113; 07/21/2017

    Really struggling with the following:

    I would like to join t_instrument_price with itself ON InstrumentID AND on the closest earlier date in order to get the previous available price (not necessarily the previous day as there are no prices during weekend/holidays.etc) . Up until now I didn't manage to come close to a solution. Can anybody help? Would be very appreciated...

    expected result

    InstrumentID InstrumentPrice PriceDate PreviousPrice PreviousDatePrice
    1 82.03 07/25/2017 82.08 07/24/2017
    1 82.08 07/24/2017 81.97 07/21/2017
    2 115 07/25/2017 114.5 07/24/2017
    2 114.5 07/24/2017 113 07/21/2017

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    This can be done using a subquery:

    http://allenbrowne.com/subquery-01.html

  3. #3
    wijo85 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2017
    Posts
    3
    Thank you...found it..has been years since I wrote my last query so this helped

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 09-03-2015, 04:38 PM
  2. Replies: 10
    Last Post: 05-15-2015, 11:35 AM
  3. Query to join records with the closest values
    By dipique in forum Queries
    Replies: 2
    Last Post: 09-08-2014, 04:11 PM
  4. Replies: 4
    Last Post: 05-28-2014, 10:09 AM
  5. Find Variables closest to specified Date
    By crimedog in forum Reports
    Replies: 1
    Last Post: 01-30-2014, 11:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums