sql sum查询资金总额为空问题

来源:互联网 发布:c语言角度转弧度 编辑:程序博客网 时间:2024/05/04 15:19

查询用户收入总额

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结果

0 0
原创粉丝点击