gpt4 book ai didi

mysql - 计算 MySQL select 语句的最大值之和

转载 作者:行者123 更新时间:2023-11-29 06:53:02 26 4
gpt4 key购买 nike

阅读类似的线程,但我找不到这不起作用的原因:

select sum(max(i.invoice_total)) as 'Sum of Largest Unpaid Invoice'
from (select vendor_id, MAX(invoice_total)
from vendors v join invoices i using (vendor_id)
where i.payment_date is null
group by v.vendor_id) as alias;

这不是应该计算最大invoice_total的总和吗?当我在最大值前面添加总和时,不断出现“未知列”错误。

最佳答案

您需要为该列命名。 。 。我会明确地这样做:

select sum(max_invoice_total) as `Sum of Largest Unpaid Invoice`
from (select vendor_id, MAX(invoice_total) as max_invoice_total
from vendors v join
invoices i
using (vendor_id)
where i.payment_date is null
group by v.vendor_id
) alias;

关于mysql - 计算 MySQL select 语句的最大值之和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46737047/

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