关于Postgresql上一个相当具体的查询的问题

时间:2013-11-19 20:50:57

标签: sql postgresql inner-join

SELECT 
    Account_Invoice.amount_untaxed
    ,right(Res_Partner.vat, length(Res_Partner.vat) - 2) AS RFC
FROM Account_Invoice
INNER JOIN Res_Partner ON Account_Invoice.partner_id = Res_Partner.id
INNER JOIN Account_Invoice_Tax ON Account_Invoice.id = Account_Invoice_Tax.invoice_id
WHERE account_invoice.journal_id = 2
    AND account_invoice.date_invoice >= '2013-01-01'
    AND account_invoice.date_invoice <= '2013-02-01'
    AND account_invoice.reconciled IS TRUE
    AND account_invoice_tax.account_id = 3237
    AND account_invoice.amount_tax >= 0;

这将返回未分配的值以及公司的唯一代码。

问题是,其中一些不返回增值税代码,因为account_invoice内的值有很多行,其中一些partner_id链接到res_partner,其中vat res_partner列为空。然而,其中一些线路链接到{{1}}中有正确的增值税代码的一行,您是否知道如何“忽略”未链接到正确增值代码的行?

1 个答案:

答案 0 :(得分:1)

添加一个条件`AND Res_partner.vat IS NOT NULL'

查询将停止返回res_partner不包含vat值的记录。

我假设无效的桶值为NULL