【问题标题】:#1111 - Invalid use of group function in case statement mysql?#1111 - 在 case 语句 mysql 中使用组函数无效?
【发布时间】:2015-07-20 19:44:53
【问题描述】:

我想从表中检索到期日期,我使用了以下查询,但它返回 invalid use of group function 错误。我的查询有什么问题?

下面给出我的查询,

   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

【问题讨论】:

    标签: php mysql sql sum data-retrieval


    【解决方案1】:

    也许你想要这个。我删除了你的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 
    

    【讨论】:

    • 感谢您的回答.. 似乎工作正常.. 让我深入了解一下 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-14
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-27
    相关资源
    最近更新 更多