select tt.*,(able_amount+incomeAbleTotalAmount- payableTotalAmount) as totalAmount from(
select account_id, dept_id AS deptId , able_amount, IFNULL((select sum(pending_payment) from t_trade_project where trade_status=5 and apply_dept_id =t.dept_id ),0)incomeAbleTotalAmount,IFNULL((select sum(pending_payment) from t_trade_project where trade_status=5 and trade_dept_id =t.dept_id ),0)payableTotalAmount, create_time, update_time, is_del, remark,(SELECT dept.dept_name FROM sys_dept dept WHERE dept.dept_id = deptId)AS dept_name from t_account t
<where>
<where>
<iftest="deptId != null "> and dept_id = #{deptId}</if>
<iftest="deptId != null "> and t.dept_id = #{deptId}</if>
<iftest="ableAmount != null "> and able_amount = #{ableAmount}</if>
<iftest="ableAmount != null "> and t.able_amount = #{ableAmount}</if>
<iftest="isDel != null and isDel != ''"> and is_del = #{isDel}</if>
<iftest="isDel != null and isDel != ''"> and t.is_del = #{isDel}</if>