select id,patient_name,hospital_name,
TIMESTAMPDIFF(YEAR, data_content->>'$.userInfo.patient_birth', CURDATE()) as patient_age,
data_content->>'$.userInfo.patient_height' as patient_height,
data_content->>'$.userInfo.patient_weight' as patient_weight,
data_content->>'$.userInfo.patient_gender' as patient_gender,
data_content->>'$.report_type' as report_type,
data_content->>'$.report.stepPhase' as stepPhase,
json_extract(data_content->>'$.report.stepPhase','$.相位图."站立相中期"') as 站立相中期
from mrc_report
where hospital_name = '积水潭医院' and report_type != "balance"
Invalid JSON text in argument 1 to function json_extract: "The document is empty." at position 0.
我检查了数据集,report.stepPhase确实有几个空的。我尝试了把json_valid(data_content->>'$.report.stepPhase')加在了最后的where条件中,能够出结果,但是结果不包括空值的几条数据
from mrc_report
where hospital_name = '积水潭医院' and report_type != "balance"
and json_valid(data_content->>'$.report.stepPhase')
这个结果是不包括空数据的,如果某条数据为空,保留report_type前的信息,最后一列显示为null
条件加下面不行,那就加上面呗
select id,patient_name,hospital_name,
case when json_valid(data_content->>'$.report.stepPhase') then
data_content->>'$.report.stepPhase' end as stepPhase
from mrc_report
where hospital_name = '积水潭医院' and report_type != "balance"