Using the Sample of json values attached below , im unable to select all attributes of the json where receivedstatus='YES' and those that receivedstatus='No' not to show up .
[
{
"itemCode": "LAB-BIOCHEM-0007",
"serviceName": "Blood Gas Test",
"qty": "1",
"rate": "5000.0",
"total": "5000.0",
"classification": "",
"department": "LABORATORY",
"inputDate": "2023-02-09",
"paymentStatus": "",
"receivedStatus": "YES",
"processed": "",
"cmTotal": "0.0",
"receivingUsername": "",
"processingUsername": "",
"approvalStatus": "",
"specimen": "",
"doctorsRequestingName": ""
},
{
"itemCode": "LAB-SEROL-001",
"serviceName": "Anc Profile",
"qty": "1",
"rate": "3000.0",
"total": "3000.0",
"classification": "",
"department": "LABORATORY",
"inputDate": "2023-02-09",
"paymentStatus": "",
"receivedStatus": "NO",
"processed": "",
"cmTotal": "0.0",
"receivingUsername": "",
"processingUsername": "",
"approvalStatus": "",
"specimen": "",
"doctorsRequestingName": ""
},
{
"itemCode": "LAB-PARAS-001",
"serviceName": "B/S For Mps",
"qty": "1",
"rate": "200.0",
"total": "200.0",
"classification": "",
"department": "LABORATORY",
"inputDate": "2023-02-09",
"paymentStatus": "",
"receivedStatus": "YES",
"processed": "",
"cmTotal": "0.0",
"receivingUsername": "",
"processingUsername": "",
"approvalStatus": "",
"specimen": "",
"doctorsRequestingName": ""
},
{
"itemCode": "LAB-MICROB-012",
"serviceName": "Hvs Wet Prep And Gram Stain ",
"qty": "1",
"rate": "500.0",
"total": "500.0",
"classification": "",
"department": "LABORATORY",
"inputDate": "2023-02-09",
"paymentStatus": "",
"receivedStatus": "NO",
"processed": "",
"cmTotal": "0.0",
"receivingUsername": "",
"processingUsername": "",
"approvalStatus": "",
"specimen": "",
"doctorsRequestingName": ""
}
]
I tried running the following Query but it is returning all the values whether received status is yes or not
Select
*
from (
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');