加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

关于:警告: 聚合或其他 SET 操作消除了空值。

发布时间:2020-12-14 02:09:23 所属栏目:百科 来源:网络整理
导读:转载地址:http://www.xuebuyuan.com/782746.html create table tb ( id int, num int ) insert into tb select 1,10 insert into tb select 1,20 insert into tb select 2,80 insert into tb select 2,null select id,sum(num) from tb group by id id ----

转载地址:http://www.xuebuyuan.com/782746.html

create table tb
(
id int,
num int
)

insert into tb select 1,10
insert into tb select 1,20
insert into tb select 2,80
insert into tb select 2,null

select id,sum(num)
from tb
group by id

id
----------- -----------
1 30
2 80

(所影响的行数为 2 行)

警告: 聚合或其它 SET 操作消除了空值。

分析:聚合函数无法对null值进行运算,所以会忽略
这个提示仅仅是警告,就是告诉用户,null值被忽略了
结果就是按照null为0来计算

如果用
select id,sum(isnull(num,0))
from tb
group by id

这样的语句,在运算之前,isnull已经把null值转换成0了, 所以聚合函数运算就没有问题

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读