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 571187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:28:51+00:00 2026-05-13T13:28:51+00:00

I have a table filled with purchase prices, like this: sku price btw startdate

  • 0

I have a table filled with purchase prices, like this:

sku                   price    btw   startdate
PCR-CA5425023181515   21,17 €   1    01/01/2009
PCR-CA5425023181515  999,00 €   1    06/06/2009
PCR-CA5425023181515  444,00 €   4    09/07/2009
PCR-CA5425023181515  100,00 €   4    10/08/2009

I have another table filled with orders, like this:

sku                  quantity   orderdate
PCR-CA5425023181515     5       01/05/2009
PCR-CA5425023181515    10       01/12/2009
PCR-CA5425023181515    10       24/12/2009

My goal is to get every purchase price per order from that date.
(For example: when I ordered the product on the first of may (01/05) it cost 21,17 euros.
When I ordered it on the first of december (01/12) it cost 100,00 euros.)

I’ve been struggling with this for the past hour, but haven’t found anything useful yet.

  • 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-13T13:28:51+00:00Added an answer on May 13, 2026 at 1:28 pm
    SELECT
         O.sku,
         O.qty,
         PP.price
    FROM
         Orders O
    INNER JOIN Purchase_Prices PP ON
         PP.sku = O.sku AND
         PP.start_date <= O.order_date
    WHERE
         NOT EXISTS
         (
              SELECT
                   *
              FROM
                    Purchase_Prices PP2
              WHERE
                    PP2.sku = PP.sku AND
                    PP2.start_date <= O.order_date AND
                    PP2.start_date > PP.start_date
         )
    

    Alternatively:

    SELECT
         O.sku,
         O.qty,
         PP.price
    FROM
         Orders O
    INNER JOIN Purchase_Prices PP ON
         PP.sku = O.sku AND
         PP.start_date <= O.order_date
    LEFT OUTER JOIN Purchase_Prices PP2 ON
         PP2.sku = O.sku AND
         PP2.start_date <= O.order_date AND
         PP2.start_date > PP.start_date
    WHERE
         PP2.sku IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a NSMutableArray filled with NSMutableArray's. I would like to fill my table
I have a department table filled with records. I would like to run a
I have a customer table filled with customer detail and I would like to
I have 1 table filled with articles. For the purpose of this post, lets
I have a person table filled with Person information. I would like to get
I have a data table filled with text in each table row. How do
I have an HTML table filled with a number of rows. How can I
I have a question on calculating times. I have a simple table filled with
I have a table with three filled columns named Name, City and Occupation. I
I have a table cell that isn't entirely filled with text so the bg

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.