您的位置:首页 > 数据库

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

2015-11-15 14:08 393 查看
查询用户收入总额

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结果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sql sum