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结果
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中的三值逻辑
- SQL Server 作业批量停止
- 结束SQL阻塞的进程
- 动态生成SQL Server视图作业
- SQL Server 语句操纵数据库
- SQL(结构化查询语句)
- oracle sql日期比较
- linux快速部署mysql服务器
- sql 存储过程分页
- 在WINXP系统上安装SQL Server企业版的方法
- 通过批处理调用SQL的方法(osql)
- SQL Server 存储过程的分页
- ASP程序与SQL存储过程结合使用详解
- SQL SERVER编写存储过程小工具
- 防御SQL注入攻击时需要注意的一个问题
- PostgreSQL教程(十九):SQL语言函数
- SQL Server复制需要有实际的服务器名称才能连接到服务器
- SQL Server 2000向SQL Server 2008 R2推送数据图文教程