Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
计算MySQL select语句的最大值之和_Mysql_Sql_Sum_Max - Fatal编程技术网

计算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(变量))的行