我无法选择Maria Db中满足特定条件的JSON列中的所有值。数据库字段中的数据被组织为JSON数组中的多个项目。
例如,如何检索 * 所有gson值 *,其中 receivedStatus 为 YES?
下面是我的示例数据
[{"itemCode":"LAB-BLOOD-TRAN-0001","serviceName":"Blood Crosmatching","qty":"1","rate":"1500.0","total":"1500.0","classification":"","department":"LABORATORY","inputDate":"2023-02-09","paymentStatus":"NO","receivedStatus":"YES","processed":"","cmTotal":"0.0","receivingUsername":"","processingUsername":"","approvalStatus":"","specimen":"","doctorsRequestingName":""},
{"itemCode":"LAB-BIOCHEM-0001","serviceName":"ALBUMIN","qty":"1","rate":"500.0","total":"500.0","classification":"","department":"LABORATORY","inputDate":"2023-02-09","paymentStatus":"NO","receivedStatus":"NO","processed":"","cmTotal":"0.0","receivingUsername":"","processingUsername":"","approvalStatus":"","specimen":"","doctorsRequestingName":""},
{"itemCode":"LAB-IMMUN-001","serviceName":"17 Beta Estradiol ","qty":"1.0","rate":"4500.0","total":"4500.0","classification":"IMMUNOLOGY","department":"LABORATORY","inputDate":"2023-02-09 17:01:27","paymentStatus":"YES","receivedStatus":"","processed":"","cmTotal":"4500.0","receivingUsername":"","processingUsername":"","approvalStatus":"APPROVED","specimen":"Urea","doctorsRequestingName":""},
{"itemCode":"LAB-IMMUN-004","serviceName":"Acetyl Receptor Antibodies ","qty":"1","rate":"12500.0","total":"12500.0","classification":"","department":"LABORATORY","inputDate":"2023-02-09","paymentStatus":"NO","receivedStatus":"NO","processed":"","cmTotal":"0.0","receivingUsername":"","processingUsername":"","approvalStatus":"","specimen":"","doctorsRequestingName":""}]
我试过:
从(中选择 *
SELECT distinct patient_name,age,visit_no,sex,laboratory_requests,JSON_UNQUOTE(JSON_EXTRACT(t.laboratory_requests, CONCAT('$[', x.seq, '].department'))) AS department,
JSON_UNQUOTE(JSON_EXTRACT(t.laboratory_requests, CONCAT('$[', x.seq, '].receivedStatus'))) AS receivedStatus
FROM pb_doctors_requests t
INNER JOIN (
SELECT seq FROM seq_0_to_10
) AS x ON JSON_EXTRACT(t.laboratory_requests, CONCAT('$[', x.seq, ']')) IS NOT NULL
) as s
where receivedStatus in ('NO');
我正在尝试的截图:
enter image description here
1条答案
按热度按时间ljsrvy3e1#
尝试以下操作,通过键编号获取特定元素的值:
如果要删除报价,请使用
JSON_UNQUOTE
:要获取所有数组元素的值,可以使用
JSON_TABLE
:这是mariadb 10.3的工作版本:
Demo for mysql 8/ mariadb 10.6 and higher
Demo for mariadb 10.3