MS-Access 获取特定订单日期的产品价格

发布于 2024-08-17 17:04:29 字数 659 浏览 3 评论 0原文

我有一张桌子,里面装满了购买价格,如下所示:

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

我还有一张桌子,里面装满了订单,如下所示:

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

我的目标是获取从该日期起每个订单的每个购买价格。 (例如:当我在 5 月 1 日(01/05)订购产品时,价格为 21.17 欧元。 当我在 12 月 1 日(2012 年 1 月)订购时,花费了 100,00 欧元。)

在过去的一个小时里我一直在努力解决这个问题,但还没有找到任何有用的东西。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情愿 2024-08-24 17:04:29
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
     )

或者:

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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文