Null 值会被聚合函数忽略,默认情况下,Sql Server会给出Warning:

Warning: Null value is eliminated by an aggregate or other SET operation.

这个Warning说明Null value 被聚合函数忽略,此时的 SET ANSI_WARNINGS 选项是ON状态,例如,count()函数不会计算null值,min/max函数不会计算null值。如果设置 SET ANSI_WARNINGS OFF ,SQL Server不会抛出 warning 消息。

1,忽略NULL 值

例如,结果是1,正确,但是出现一个Warning。

use tempdb
go set ANSI_WARNINGS on if object_id('#dt_test','U') is not null
drop table #dt_test create table #dt_test
(
id int
) insert into #dt_test
values(1),(null) select min(id)
from #dt_test

强烈推荐:将ANSI_Warnings选项设置为ON

2,查看当前DB的 ANSI_Warnings 选项的设置

select name,
database_id,
is_ansi_warnings_on
from sys.databases
where database_id=db_id()

引用《SET ANSI_WARNINGS》:

As the Warning says, NULLs are being ignored because we are using aggregate function (SUM, AVG). To avoid the warning we can use “set ansi_warnings off” before the script. Here is the modified script.

SET ANSI_WARNINGS OFF

When set to ON, if null values appear in aggregate functions, such as SUM, AVG, MAX, MIN, STDEV, STDEVP, VAR, VARP, or COUNT, a warning message is generated. When set to OFF, no warning is issued.

SET ANSI_WARNINGS must be ON when you are creating or manipulating indexes on computed columns or indexed views. If SET ANSI_WARNINGS is OFF, CREATE, UPDATE, INSERT, and DELETE statements on tables with indexes on computed columns or indexed views will fail

参照文档:

SET ANSI_WARNINGS (Transact-SQL)

Warning: Null value is eliminated by an aggregate or other SET operation.的更多相关文章

  1. SQL笔记1:SELECT及SELECT高级应用

      T-SQL笔记1:SELECT及SELECT高级应用 本章摘要 1:安装AdventureWorks 2:基本运算符和表达式 3:between 4:like 5:escape 6:TOP 7:G ...

  2. All 关键字

    本文档已存档,并且将不进行维护. GROUP BY 子句和 ALL 关键字 SQL Server 2005 Transact-SQL 在 GROUP BY 子句中提供 ALL 关键字.只有在 SELE ...

  3. 转载:oracle null处理

    (1)NULL的基础概念,NULL的操作的基本特点NULL是数据库中特有的数据类型,当一条记录的某个列为NULL,则表示这个列的值是未知的.是不确定的.既然是未知的,就有无数种的可能性.因此,NULL ...

  4. 0, \0, NULL

    字符串.字符数组输入.输出与'\0'的问题 原创首发,欢迎转载! 作者按 字符串.字符数组以"%s"格式输入时,以遇到'空格'为这个字符串输入结束. 字符串.字符数组以" ...

  5. MongoDB(七):聚合aggregate

    1. 聚合aggregate 聚合主要用于计算数据,类似sql中的sum().avg() 语法: db.集合名称.aggregate([{管道:{表达式}}]) stu准备的数据: db.stu.in ...

  6. mongodb 聚合(aggregate)

      MongoDB中文手册|官方文档中文版 https://docs.mongoing.com/ 聚合操作处理数据记录和 return 计算结果.聚合操作将来自多个文档的值组合在一起,并且可以对分组数 ...

  7. Oracle性能诊断艺术-读书笔记

    create table test0605 as select * from dba_objects; select t1.owner,t1.object_name,t1.object_id from ...

  8. 庖丁解牛-----Live555源码彻底解密(根据MediaServer讲解Rtsp的建立过程)

    live555MediaServer.cpp服务端源码讲解 int main(int argc, char** argv) { // Begin by setting up our usage env ...

  9. Python的Profilers性能分析器

    关于Python Profilers性能分析器 关于性能分析,python有专门的文档,可查看:http://docs.python.org/library/profile.html?highligh ...

随机推荐

  1. Windows server 修改mysql端口

    [此方法对mysql免安装版本适用] (最好先停止mysql服务) 1.解压MySQL后,在MySQL根目录下有一个my-default.ini,将该文件复制粘贴一份,重命名为:my.ini,还是放在 ...

  2. 我对C#的理解

    C#里面所有东西都可以看作对象.接口,类,枚举等等. 类是最常用的,可以继承别的接口,类等,就会自动拥有别人的功能. 接口是类的概要.给别人看的协议,好像一个人对外做出的承诺. 抽象类是实现了部分承诺 ...

  3. Django-数据模型

    修改model.py文件 from django.db import models # Create your models here. class Question(models.Model): q ...

  4. u3d avatar部件的理解

    u3d中带动画的fbx文件导入的时候,就会显示一个avatar组件,这个到底干嘛的一直没能很好的理解,翻看网上的介绍,基本都是告诉你,设置humanoid类型动画时,拖拉过去之类,但是这玩意到底存储了 ...

  5. Oracle Blob 字段的模糊查询

    原文地址:http://blog.csdn.net/springk/article/details/6866248

  6. Windows & Office完美结合,助力办公

    虚拟桌面——休闲工作分开来 Windows 10最令我欣愉的是加入了虚拟桌面的功能. 作为一名拖延症晚期患者,早已病入膏肓.每次工作时总会不知不觉地将实现转移到已经打开的浏览器及聊天工具上,时间就这样 ...

  7. 【随记】Hello World小记

    今天装Python,如下: 突然想到,到现在,我已经数不清写过多少遍Hello World了. 最早是初一学VB的时候,用Label1在Form1上画一个,然后修改Caption属性为“Hello W ...

  8. nginx实时记录请求状态信息( ngx_realtime_request_module)

    cd /usr/local/src/ wget "http://nginx.org/download/nginx-1.4.2.tar.gz" tar -xzvf nginx.tar ...

  9. Android—LayoutInflater学习笔记

    LayoutInflater的的主要用处:使用LayoutInflater来载入界面,类似于findViewById()在Activity中加载Widget组件一样.区别在于与LayoutInflat ...

  10. zabbix3.2安装graphtree3.0.4

    下载graphtree3.0.4 wget https://raw.githubusercontent.com/OneOaaS/graphtrees/master/graphtree3-0-1.pat ...