计算两个不同表的两个列之间的差异

问题描述 投票:0回答: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
sql rdbms erpnext
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.