mysql queries the data of a specific field in the entire json

Recently discovered the powerful function of mysql, you can directly query the data of a specific value in the entire json:
The field content corresponding to json is like this:
The content corresponding to msg_content is the json field:

{
    
    
    "fileName":"测非编1.mp4",
    "filePath":"/mnt/windows/folderscan/uploadAndTask/91/测非编1.mp4",
    "taskName":"截取首帧失败",
    "taskFailStage":"1"
}

The original data is like this:
Insert picture description here

 SELECT
	id,
	msg_code AS msgCode,
	read_flag AS readFlag,
	msg_content ->> '$.mediaId' as mediaId,
	msg_content ->> '$.fileName' as fileName,
	msg_content ->> '$.taskName' as taskName,
	msg_content ->> '$.filePath' as filePath
FROM
	notice_msg
WHERE
	receive_user_id = '79'

The result after splitting the query is this:
Insert picture description here
when the field is a json array:

[
    {
    
    
        "time": 1594034025178,
        "stage": 1,
        "detail": [
            {
    
    
                "stage": 1,
                "stepName": "视频信息获取",
                "createTime": 1594034024803,
                "stepStatus": 1
            },
            {
    
    
                "stage": 1,
                "stepName": "首帧截取",
                "createTime": 1594034025141,
                "stepStatus": 1
            },
            {
    
    
                "stage": 1,
                "stepName": "预处理",
                "createTime": 1594034025178,
                "stepStatus": 1
            }],
        "status": 1
    },
    {
    
    
        "time": 1594034025202,
        "stage": 2,
        "detail": [
            {
    
    
                "stage": 2,
                "stepName": "基础数据入库",
                "createTime": 1594034025202,
                "stepStatus": 1
            }],
        "status": 1
    },
    {
    
    
        "time": 1594034650094,
        "stage": 3,
        "detail": [
            {
    
    
                "stage": 3,
                "explain": "引擎识别人脸为空",
                "stepName": "本地引擎人脸检测",
                "createTime": 1594034616695,
                "stepStatus": 1
            },
            {
    
    
                "stage": 3,
                "explain": "识别结果81条",
                "stepName": "本地引擎音频检测",
                "createTime": 1594034616765,
                "stepStatus": 1
            },
            {
    
    
                "stage": 3,
                "explain": "识别结果46个",
                "stepName": "本地引擎场景检测",
                "createTime": 1594034616838,
                "stepStatus": 1
            },
            {
    
    
                "stage": 3,
                "explain": "拆条结果297条",
                "stepName": "智能拆条",
                "createTime": 1594034650094,
                "stepStatus": 1
            },
            {
    
    
                "stage": 3,
                "explain": "标签结果6条",
                "stepName": "智能标签",
                "createTime": 1594034622152,
                "stepStatus": 1
            }],
        "status": 1
    }]

Get the values ​​of all stages under all detail arrays:

select media_id as mediaId, task_content->'$[*].detail[*].stepStatus' as statusList from hisi_task_process
where media_id = '8a0cb043-98cd-4e60-b633-8309715bcea6'

Insert picture description here
[*]You can fill in the index of the array, and you can locate the first value in the array.

Guess you like

Origin blog.csdn.net/qq_32115447/article/details/106625188