Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 计算两个不同表的两列之间的差异_Sql_Rdbms_Erpnext - Fatal编程技术网

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

Sql 计算两个不同表的两列之间的差异,sql,rdbms,erpnext,Sql,Rdbms,Erpnext,我想计算采购订单金额和采购发票金额之间的差额。但我无法获取采购发票金额,即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 A

我想计算采购订单金额和采购发票金额之间的差额。但我无法获取采购发票金额,即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
您正在使用左联接。这意味着,当您的第二个表没有与第一个表匹配的数据时,您将不会从第二个表收到任何数据,但您的第一个表将返回其所有数据

您可能应该检查您的连接条件。如果您想要以您想要的方式连接这两个表,那么对pi.grand_total列使用NVL函数。因为它在左边连接,它可能有一个空值,因此空值减去po.grand_total将得到空值。NVL函数将空值转换为预期值,如NVLpi.grand_total,0


这是什么意思:但是我不能去拿。你能再解释一下吗?另外,您的数据库是什么?请将RDBMS标签附在您的问题上,并解释加入条件中的po.name和pi.parent是什么?@Pankaj_Dwivedi po=采购订单和pi=采购发票。采购订单是一个表,采购发票是另一个表。@VBoka我没有得到pi.grand_total列的任何值。你能帮我吗?嗨,我解释错了。对不起,我的坏@VBoka