示例
------------------------------------------
Amount | Type
------------------------------------------
1000 | credit
------------------------------------------
4500 | credit
------------------------------------------
1250 | debit
------------------------------------------
500 | credit
------------------------------------------
select IFNULL(SUM(amount),0) as Credit_Amount,IFNULL(SUM(amount),0) as Debit_Amount,
type,party from receipt where party='$list[id]' and type='credit' or
type='debit'
输出
Credit_Amount = 6000
Debit_Amount = 1250
如果类型为credit,则值应添加credit
变量,如果type为debit,则值应添加debit
。请帮我解决这个问题。
答案 0 :(得分:2)
这是信用查询,只能根据要求追加。
Select IF(type='Credit', SUM(amount), null) as Credit from receipt