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. jboss [how to access the admin console]

    However you have not yet added any users to be able to access the admin console. 进入%EAP_HOME%/bin 执行 ...

  2. [Leetcode][JAVA] Minimum Window Substring

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  3. LR loadrunner参数化-笔记

      LR在录制程序运行的过程中,VuGen(脚本生成器) 自动生成了包含录制过程中实际用到的数值的脚本,如果你企图在录制的脚本中使用不同的数值执行脚本的活动(如查询.提交等等),那么你必须用参数值取代 ...

  4. Java学习笔记四——运算符

    算术运算符 加减乘除(+.-.*./)就不说了. 求余运算符% 描述:第一个操作数除以第二个操作数,得到一个整除的结果后剩下的值就是余数 注意:求余预算的结果不一定总是整数,当操作数是浮点数时,结果可 ...

  5. 萝卜白菜,给有所爱——C#和JAVA都会终将被时代淘汰

    看到园子里又有一波试图掀起C#和JAVA的谁更好的争论,对于这些一直不断的争论,我觉得实在没有必要,黑格尔的存在即合理,中国的老古语说的萝卜白菜各有所爱,大家争论的再多其实卵用也没用,还不如趁着闲暇时 ...

  6. Windows下Oracle安装图解----oracle-win-64-11g 详细安装步骤

    一. Oracle 下载 官方下地址 http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.htm ...

  7. 道路翻新 (Revamping Trails, USACO 2009 Feb)

    题意:给定m<=50000的1-n有联通的图,求最多可以使K<=20条边变为0的情况下的最短路是多少.. 思路:简单的分层图最短路,对于每个点拆成K个点.. 然后求一边最短路.. code ...

  8. HTML5-格式化

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  9. (转)Linux服务器调优

    Linux内核参数 http://space.itpub.net/17283404/viewspace-694350 net.ipv4.tcp_syncookies = 1 表示开启SYN Cooki ...

  10. lxc on centos

    终于把lxc的网络配通了,也不知道对不对,记一下 一开始都是雷同的地方 yum install libcgroup lxc lxc-templates 安装lxc cgroup 然后记得 chkcon ...