-1

我想计算采购订单金额和采购发票金额之间的差额。但我无法获取采购发票金额,即“pi.grand_total”,因此也无法获取“(pi.grand_total - po.grand_total)”的差额。请帮助。以下是我的查询。PO = 采购订单 PI = 采购发票

 SELECT DISTINCT
    po.name AS "PO #:Link/Purchase Order:120",
    po.supplier AS "Supplier:Link/Supplier:120",
    po.Company AS "Company:Data:120",
    po.currency AS "Currency:Link/Currency:120",
    po.base_grand_total AS "Grand Total:Currency:120",
    po.status AS "Status:Data:120",
    po.per_received AS "Per Received:Data:120",
    CEILING(po.per_billed) AS "Per Billed:Data:120",
    po.delivery_date AS "Delivery Date:Date:120",
    pi.grand_total AS "Final PI Total:120",
    (pi.grand_total - po.grand_total) AS "Amount Difference:120"
    FROM
    "tabPurchase Order" as po
    LEFT JOIN "tabPurchase Invoice" as pi ON po.name = pi.parent
    WHERE

    po.per_received = 100
    AND
    CEILING(po.per_billed) < 100
    ORDER BY po.delivery_date ASC
4

1 回答 1

1

您正在使用LEFT JOIN. 这意味着当您的第二个表没有与您的第一个表匹配的数据时,您将不会收到来自第二个表的数据,但您的第一个表将返回其所有数据。

您可能应该检查您的加入条件。如果您想以您想要的方式连接这两个表,请使用NVLFunction for pi.grand_total 列。因为它在左连接,所以它可能有一个 NULL 值,因此 NULL 减去 po.grand_total 会给你 NULL。NVL函数将 NULL 值转换为预期值,例如NVL(pi.grand_total,0)

连接如何工作的一个很好的例子

于 2020-02-26T08:08:36.397 回答