How can an empty traffic interval explicitly encode an undefined rate?
NULLIF yields NULL when its arguments compare equal. Replacing a zero denominator with NULL expresses an undefined ratio.
SQLite example and interpretation
An interval with no requests differs from an interval where every request failed. Displaying zero for both loses that distinction.
WITH r(ok,n) AS (VALUES(0,0),(0,4)) SELECT n,1.0*ok/nullif(n,0) FROM r ORDER BY n;Result [[0, null], [4, 0.0]]
中文
没有请求的时间段如何表示成功率分母为零?
NULLIF 在两个参数相等时产生 NULL,可将零分母转为缺失,从公式上表达该比率未定义。
SQLite 示例与适用条件
零请求的成功率和有请求但全部失败是两种情形。展示层若都填成零,就无法区分。
WITH r(ok,n) AS (VALUES(0,0),(0,4)) SELECT n,1.0*ok/nullif(n,0) FROM r ORDER BY n;结果 [[0, null], [4, 0.0]]