估计是有人已经删除了0的记录
结论:
1。当被除数为0时“Divide by zero error encountered.”
2。在ORACLE和SQL Server中,(any number)/null结果都为NULL
试验
select @@version
-----------------------------------------------------------------
Microsoft SQL Server 2012 - 11.0.5343.0 (X64)
May 4 2015 19:11:32
Copyright (c) Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.1 (Build 7601: Service
Pack 1) (Hypervisor)
create table demo (id int, a int, b int)
insert into demo values(1,1,1)
insert into demo values(2,2,0)
insert into demo (id, a) values(3,3)
case 1:
select A/B, row_number() over (order by ID)
from demo
where id=1
----------- --------------------
1 1
case 2:
select A/B, row_number() over (order by ID)
from demo
where id=2
----------- --------------------
Msg 8134, Level 16, State 1, Line 1
Divide by zero error encountered.
case 3:
select A/B, row_number() over (order by ID)
from demo
where id=3
----------- --------------------
NULL 1