计算MySQL select语句的最大值之和
阅读类似的文章,但我找不到这不起作用的原因:计算MySQL select语句的最大值之和,mysql,sql,sum,max,Mysql,Sql,Sum,Max,阅读类似的文章,但我找不到这不起作用的原因: 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; 这不应该计
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;
这不应该计算最大发票总额吗?当我将总和添加到最大值之前时,一直给我“未知列”错误。您需要命名列。我要明确地这样做:
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;
您需要为列命名。我要明确地这样做:
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;
尝试此操作-为max(invoice_total)指定一个别名,然后在外部选择中使用该别名:
select sum(max_invoice) as 'Sum of Largest Unpaid Invoice'
from (select vendor_id, MAX(invoice_total) as max_invoice
from vendors v join invoices i using (vendor_id)
where i.payment_date is null
group by v.vendor_id) as alias;
尝试此操作-为max(invoice_total)指定一个别名,然后在外部选择中使用该别名:
select sum(max_invoice) as 'Sum of Largest Unpaid Invoice'
from (select vendor_id, MAX(invoice_total) as max_invoice
from vendors v join invoices i using (vendor_id)
where i.payment_date is null
group by v.vendor_id) as alias;
您需要在内部查询中为Max(发票总额)别名。不能有类似于(sum(Max(变量))的行。您需要在内部查询中为Max(发票总额)别名。不能有类似于(sum(Max(变量))的行