1. 程式人生 > >MySQL SUM()函式按條件求和

MySQL SUM()函式按條件求和

  • 一般求和
select sum(money) from user group by id;
  • 按條件求和
select sum(if(type=1,money,0)) from user group by id;