我想从表中检索due_date,我使用了以下查询,但它返回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
答案 0 :(得分:2)
也许你想要这个。我在案例中移除了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