以下は私が使用しているクエリです
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
このクエリはどのように修正できますか?