gpt4 book ai didi

sql - 对从 postgresql 中的查询获得的值进行排序

转载 作者:行者123 更新时间:2023-11-29 13:32:35 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com