Where should a quality condition go when devices with no good readings must survive?

A quality predicate in the ON clause of a LEFT JOIN restricts eligible matches while preserving the device roster.

SQLite example and interpretation

Device B has only a failed reading and still appears with a missing value. A WHERE filter requiring a good right-side status would discard it.

WITH d(id) AS (VALUES('A'),('B')), r(id,ok,v) AS (VALUES('A',1,7),('B',0,9)) SELECT d.id,v FROM d LEFT JOIN r ON d.id=r.id AND r.ok=1 ORDER BY d.id;

Result [["A", 7], ["B", null]]

中文

保留无合格测量的设备时,质量条件应放在哪里?

把质量条件放入 LEFT JOIN 的 ON,能在寻找匹配时排除坏记录,同时保留左侧设备。

SQLite 示例与适用条件

设备 B 只有坏记录,结果仍有 B 的空读数。若在 WHERE 要求右侧状态为好,这一行会被剔除。

WITH d(id) AS (VALUES('A'),('B')), r(id,ok,v) AS (VALUES('A',1,7),('B',0,9)) SELECT d.id,v FROM d LEFT JOIN r ON d.id=r.id AND r.ok=1 ORDER BY d.id;

结果 [["A", 7], ["B", null]]

References / 参考来源

Keep reading / 继续阅读