Which alert band wins when several CASE thresholds match?

A searched CASE evaluates WHEN conditions in order and returns the first true branch.

SQLite example and interpretation

A value of 95 meets both 70 and 90. Put the severe condition first. Comparisons with missing values require an explicit missing branch or default.

WITH r(x) AS (VALUES(95),(75),(NULL)) SELECT x,CASE WHEN x IS NULL THEN 'missing' WHEN x>=90 THEN 'high' WHEN x>=70 THEN 'medium' ELSE 'low' END FROM r ORDER BY x;

Result [[null, "missing"], [75, "medium"], [95, "high"]]

中文

多条告警阈值同时命中时 SQL 取哪一档?

搜索式 CASE 按顺序检查 WHEN 条件,仅返回第一个为真的分支。

SQLite 示例与适用条件

95 同时达到 70 和 90,应将严重告警放在前面。空值比较为未知,需要显式设计缺测分支或默认值。

WITH r(x) AS (VALUES(95),(75),(NULL)) SELECT x,CASE WHEN x IS NULL THEN 'missing' WHEN x>=90 THEN 'high' WHEN x>=70 THEN 'medium' ELSE 'low' END FROM r ORDER BY x;

结果 [[null, "missing"], [75, "medium"], [95, "high"]]

References / 参考来源

Keep reading / 继续阅读