按条件求和

SUM(IF(fee_type=1,fee_for_balance,0))
count(if(bill_sec<=12, bill_sec, null))

MAX(IF(item_code like '%_mini', item_value, 0)) phone_mini,SUM(IF(item_code like '%_fee', item_value, ''))

数据示例

mysql sum求和多出好多小数 mysql求和运算_mysql

统计每月账单的金额和支付金额

select order_no,month, SUM(IF(fee_type=1,fee_for_balance,0)) bill_money,SUM(IF(fee_type=2,fee_for_balance,0)) receivable_money from test GROUP BY month