createtable students
(
name varchar,
gender varchar,
age int,
scores jsonb
);INSERTINTOpublic.students (name, gender, age, scores)VALUES('张三','男',34,'[{"语文": "78"},{"数学": "90"}]');INSERTINTOpublic.students (name, gender, age, scores)VALUES('李四','女',21,'[{"语文": "89"},{"数学": "67"}]');INSERTINTOpublic.students (name, gender, age, scores)VALUES('王二','女',27,null);select*from students ;
students
name
gender
age
scores
张三
男
34
[{“语文”: “78”}, {“数学”: “90”}]
李四
女
21
[{“语文”: “89”}, {“数学”: “67”}]
王二
女
27
NULL
pgsql
SQL
select*,(scores ->0)->>'语文' ::textas score
from students
where scores isnotnullANDexists(select1from jsonb_array_elements(students.scores) r
where r->>'语文'>'80');