查询用户收入总额
select sum(money) amount from accountcash where userid=1 and type=1
当用户没有收入记录时,返回的是null,为避免null问题可以用ifnull:
select ifnull(sum(money),0) amount from accountcash where userid=1 and type=1
sum和count不一样,count不管是否有记录都会返回非null结果
查询用户收入总额
select sum(money) amount from accountcash where userid=1 and type=1
当用户没有收入记录时,返回的是null,为避免null问题可以用ifnull:
select ifnull(sum(money),0) amount from accountcash where userid=1 and type=1
sum和count不一样,count不管是否有记录都会返回非null结果