我在Laravel 5.5 Eloquent中编写了一个查询,toSql()
返回
SELECT
`entity_type`, `entity_id`, SUM(amount) AS total
FROM
`account_journals`
WHERE
EXISTS( SELECT
*
FROM
`account_ledgers`
WHERE
`account_journals`.`ledger_id` = `account_ledgers`.`id`
AND `name` = ?
AND `account_ledgers`.`deleted_at` IS NULL)
GROUP BY `entity_type` , `entity_id`
HAVING `total` > ?
显示错误且无法运行
SQLSTATE[42000]: Syntax error or access violation: 1463 Non-grouping field
'total' is used in HAVING clause (SQL: select `entity_type`, `entity_id`,
SUM(amount) AS total from `account_journals` where exists (select * from
`account_ledgers` where `account_journals`.`ledger_id` =
`account_ledgers`.`id` and `name` = Accounts Receivable and
`account_ledgers`.`deleted_at` is null) group by `entity_type`, `entity_id`
having `total` > 0)
如果我直接运行相同的查询,它工作正常。可能是什么问题。