1.sum与if结合使用 如图:数据表中,count_money 字段可为正,可为负.为正表示收入,负表示支出. 统计总收入,总支出. select sum(if(count_money > 0, count_money, 0)) as sum_receipt, sum(if(count_money<0, count_money, 0)) as sum_paid from tableName; 得到sum_receipt为总收入,sum_paid为总支出. mysql 中if的用法: if(e…