执行SQL语句后,警告: 聚合或其他 SET 操作消除了空值。请看我的语句:

JiuchunYoung 2014-12-19 01:53:10
Update a set a.state=4 from gds_Products a
where state =0 and infotype =1 and exists
(select * from (select substring(prowbs,1,len(prowbs)-5) as prowbs,prono,max(EffectiveTime) as EffectiveTime from gds_Products where state =0 and infotype =1 --and EffectiveTime<=Getdate()
group by prono,substring(prowbs,1,len(prowbs)-5)) b where substring(a.prowbs,1,len(a.prowbs)-5) = b.prowbs and a.prono =b.prono
and a.EffectiveTime != b.EffectiveTime)
...全文
6887 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
guguda2008 2014-12-19
  • 打赏
  • 举报
回复
这是警告,不影响执行结果,就是提示你小心对NULL值的默认处理。 PS:个人觉得这是最没用的警告之一
Tiger_Zhao 2014-12-19
  • 打赏
  • 举报
回复
这只是个小提示。
比如#4的例子中,你期望id=1的数量为2,那么就需要把 COUNT(name) 改成 COUNT(*)。
查询分析器不仅仅用来修正语句错误。
还需要在语句正确的情况下,验证逻辑是否符合需求。这个小提示就是用来确认是否需要对NULL进行统计。
不影响正确的语句的执行结果。
还在加载中灬 2014-12-19
  • 打赏
  • 举报
回复
引用 5 楼 JiuchunYoung 的回复:
[quote=引用 2 楼 DBA_Huangzj 的回复:] 这个没问题的,只是告诉你group by之后消除了空值
我执行后的效果如下 : 警告: 聚合或其他 SET 操作消除了 Null 值。 (0 行受影响) @DBA_Huangzj ,请问这个意思是不是对于EffectiveTime 为空的情况不进行更新处理的意思吗?[/quote]不是,系统只是告诉你有这么一件事,某些为空EffectiveTime的情况被同组的prono,substring(prowbs,1,len(prowbs)-5) 的EffectiveTime列值覆盖
發糞塗牆 2014-12-19
  • 打赏
  • 举报
回复
这个只是告诉你会发生这个事,但是据我目前的经历,都没有发生过什么问题,所以我从来都不管
JiuchunYoung 2014-12-19
  • 打赏
  • 举报
回复
引用 2 楼 DBA_Huangzj 的回复:
这个没问题的,只是告诉你group by之后消除了空值
我执行后的效果如下 : 警告: 聚合或其他 SET 操作消除了 Null 值。 (0 行受影响) @DBA_Huangzj ,请问这个意思是不是对于EffectiveTime 为空的情况不进行更新处理的意思吗?
發糞塗牆 2014-12-19
  • 打赏
  • 举报
回复
---------------------------------------------------------------- -- Author :DBA_Huangzj(發糞塗牆) -- Date :2014-12-19 13:57:08 -- Version: -- Microsoft SQL Server 2014 - 12.0.2254.0 (X64) -- Jul 25 2014 18:52:51 -- Copyright (c) Microsoft Corporation -- Enterprise Edition (64-bit) on Windows NT 6.4 <X64> (Build 9860: ) (Hypervisor) -- ---------------------------------------------------------------- --> 测试数据:[test] if object_id('[test]') is not null drop table [test] go create table [test]([id] int,[name] varchar(1)) insert [test] select 1,'a' union all select 2,'b' union all select 1,null union all select 3,'c' --------------开始查询-------------------------- select id,count(name) from [test] group by id ----------------结果---------------------------- /* id ----------- ----------- 1 1 2 1 3 1 (4 row(s) affected) Warning: Null value is eliminated by an aggregate or other SET operation. (3 row(s) affected) */
JiuchunYoung 2014-12-19
  • 打赏
  • 举报
回复

Update a set a.state=4 from gds_Products a
where state =0 and infotype =1 
and exists (select * from (select substring(prowbs,1,len(prowbs)-5) as prowbs,prono
,max(EffectiveTime) as EffectiveTime 
from gds_Products where state =0 and infotype =1
group by prono,substring(prowbs,1,len(prowbs)-5)) b 
where substring(a.prowbs,1,len(a.prowbs)-5) = b.prowbs 
and a.prono =b.prono 
and a.EffectiveTime != b.EffectiveTime)
發糞塗牆 2014-12-19
  • 打赏
  • 举报
回复
这个没问题的,只是告诉你group by之后消除了空值
JiuchunYoung 2014-12-19
  • 打赏
  • 举报
回复

Update a set a.state=4 from gds_Products a
where state =0 and infotype =1 and exists
 (select * from (select substring(prowbs,1,len(prowbs)-5) as prowbs,prono,max(EffectiveTime) as EffectiveTime from gds_Products where state =0 and infotype =1 --and EffectiveTime<=Getdate() 
group by prono,substring(prowbs,1,len(prowbs)-5)) b where substring(a.prowbs,1,len(a.prowbs)-5) = b.prowbs and a.prono =b.prono 
and a.EffectiveTime != b.EffectiveTime)

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧