select SUM (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
or account_invoice_tax.account_id = 3236 or account_invoice_tax.account_id = 3238
我希望从3236到3237再到3238的未征税金额。我知道我必须用“分组”,但我不知道具体怎么用。有什么线索吗?
最佳答案
这对我很有用,它对3236、3237、3238的值进行排序。
select SUM(Account_Invoice.amount_untaxed) as monto,
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 in (3237,3236,3238)
and account_invoice.amount_tax >= 0
GROUP BY vat,account_invoice_tax.account_id
ORDER BY account_invoice_tax.account_id;
谢谢你们的帮助。
关于sql - 对从Postgresql中的查询获得的值进行排序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20113506/