问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
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