以下给了我一个结果:{"a":null,"b":99.0,"c":null}
我想要{"b":99.0}
一个结果,以便我可以在 JSON 补丁中使用该结果。如何使用 sqlite/json1 实现这一点?
DROP TABLE IF EXISTS test;
CREATE TABLE test (
id INTEGER PRIMARY KEY,
a REAL, b REAL, c REAL
);
INSERT INTO test(a,b,c)
VALUES (1,2,3), (1,99,3);
SELECT json_object(
'a', NULLIF(new.a, curr.a),
'b', NULLIF(new.b, curr.b),
'c', NULLIF(new.c, curr.c)
) AS result
FROM test curr
INNER JOIN test new ON curr.id
WHERE new.id = 2 AND curr.id = new.id -1 ;