我正在寻找在同一个表中加入多个 JSON 列的 Sqlite 语法。我创建了一个像这样的表:-
SQL = "CREATE TABLE BranchStock (branch VARCHAR, oldstock JSON, newstock JSON)"
....
然后我插入一些项目,如: -
INSERT INTO BranchStock VALUES('Melbourne','[{"catnumber":"ABC123","instock":5},{"catnumber":"BCD321","instock":3}]','[{"catnumber":"ABC123","instock":1},{"catnumber":"BCD321","instock":5}]');
INSERT INTO BranchStock VALUES('Sydney','[{"catnumber":"ABC123","instock":7},{"catnumber":"XYZ567","instock":0}]','[{"catnumber":"ABC123","instock":5},{"catnumber":"XYZ567","instock":3}]');
....
现在我正在寻找搜索 sql 以列出哪些分支具有 catnumber='ABC123' newstock 或 oldstock,以及库存量。也许是这样的: -
SELECT * FROM BranchStock
JOIN json_each(oldstock) ON json_valid(oldstock)
JOIN json_each(newstock) ON json_valid(newstock)
WHERE json_extract(value, '$.name')='ABC123');
以上适用于一个 JOIN,但是当我实现第二个 JOIN 时,我得到一个语法错误。
有谁知道正确的语法?提前致谢。