mysqlは、json全体の特定のフィールドのデータを照会します

最近発見されたmysqlの強力な機能により、json全体の特定の値のデータを直接クエリできます。jsonに
対応するフィールドコンテンツは次のように
なります。msg_contentに対応するコンテンツはjsonフィールドです。

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

元のデータは次のようになります。
ここに画像の説明を挿入

 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'

クエリを分割した後の結果は次のとおりです。
ここに画像の説明を挿入
フィールドがjson配列の場合:

[
    {
    
    
        "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
    }]

すべての詳細配列の下にあるすべてのステージの値を取得します:

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

ここに画像の説明を挿入
[*]配列のインデックスを入力すると、配列の最初の値を見つけることができます。

おすすめ

転載: blog.csdn.net/qq_32115447/article/details/106625188
おすすめ