下面是我正在使用的查询
SELECT
`names`, sum(cashin.amount) as amountin,
sum(cashout.amount) as amountout,
(sum(cashin.amount) - sum(cashout.amount)) as total
FROM (`client`)
INNER JOIN `cashin` ON `cashin`.`clientid`=`client`.`id`
INNER JOIN `cashout` ON `cashout`.`clientid`=`client`.`id`
WHERE (sum(cashin.amount) - sum(cashout.amount)) < 0
GROUP BY `client`.`id`
问题是我得到一个错误:
Invalid use of group function
用字段别名替换 where 子句中的函数'total'
我仍然得到一个错误:
Unknown column total
如何修复此查询?