简体   繁体   English

#1111-在case语句mysql中无效使用组函数?

[英]#1111 - Invalid use of group function in case statement mysql?

I want to retrieve due_date from table,I have used following query but it return invalid use of group function error .What is wrong with my query? 我想从表中检索due_date,我使用了以下查询,但返回invalid use of group function错误invalid use of group function查询有什么问题?

My Query given below, 我的查询如下

   select 
sum(
    case when invoices.due_date LIKE '2015-05-10%' 
        then sum(invoice_items.quantity*invoice_items.rate)-sum(IFNULL(payments.amount,0))
    end
    )as 1day, 
sum( 
    case when invoices.due_date LIKE '2015-05-09%' 
        then sum(invoice_items.quantity*invoice_items.rate)-     sum(IFNULL(payments.amount,0))
    end
    )as yesterday 
        from `invoices`
        inner join `invoice_items` on `invoice_items`.`invoice_id` = `invoices`.`id` 
        left join `payments` on `payments`.`invoice_id` = `invoices`.`id` 
        where `invoices`.`deleted_at` is null

Perhaps you want this. 也许您想要这个。 I removed your SUM() inside the case. 我删除了您的情况下的SUM()

select 
sum(
    case when invoices.due_date LIKE '2015-05-10%' 
        then (invoice_items.quantity*invoice_items.rate)-(IFNULL(payments.amount,0))
    end
    )as 1day, 
sum( 
    case when invoices.due_date LIKE '2015-05-09%' 
        then (invoice_items.quantity*invoice_items.rate)-     (IFNULL(payments.amount,0))
    end
    )as yesterday 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM