小编Rus*_* K.的帖子

操作数数据类型NULL对于max运算符无效

这段代码工作正常:

select fk, max(case when 1 = 0 then 1 else null end) maxx
    from (values(1, null), (1, null)) x(fk, a) 
    group by fk;
Run Code Online (Sandbox Code Playgroud)

输出:

fk          maxx
----------- -----------
1           NULL
Run Code Online (Sandbox Code Playgroud)

有:

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

但是这段代码:

select fk, max(a) maxx
    from (values(1, null), (1, null)) x(fk, a)
    group by fk;
Run Code Online (Sandbox Code Playgroud)

给出错误:

Msg 8117, Level 16, State 1, Line 5 Operand data type NULL is invalid for max operator.

在这两种情况下sql server计算max …

sql t-sql sql-server

7
推荐指数
1
解决办法
1332
查看次数

标签 统计

sql ×1

sql-server ×1

t-sql ×1