使用PostgreSQL 14,我有一个表'fruits',其中一个名为'items'的JSONB列包含以下示例数据:
[{"anz": 4, "typ": "Banana"}, {"anz": 5, "typ": "Apple"}, {"anz": 2, "typ": "Grapefruit"}]
[{"anz": 1, "typ": "Banana"}, {"anz": 1, "typ": "Apple"}, {"anz": 3, "typ": "Grapefruit"}]
这是可行的:
SELECT * FROM fruits WHERE items @> '[{"typ":"Apple"}]';
SELECT * FROM fruits WHERE (items -> 0 ->> 'lvl')::int > 4;
但现在我只想获取苹果有'澳新银行3'的记录.当然,将上述查询中的WHERE子句组合在一起并不合适.什么是合适的SQL?
预期输出应为标识的记录(SELECT*FROM..其中..)