有没有办法将值或变量传递到 Mysql 中的 json_path
Is there a way to pass a value or variable into json_path in Mysql
有没有办法将值或变量传递到 Mysql 中的 json_path?
我正在尝试使用 json_table 从我的 json 的 header 中获取值,然后从我得到的索引中获取内容中的日期。
在我下面的代码中,我试图传递值 jsh.cName
我的查询
Select jsh.cName, jsc.qteRecu from
DocumentField as df inner join DocumentAnchor DA on DA.currentDocId IN (
Select df.documentId from
DocumentField as df inner join DocumentAnchor DA on DA.currentDocId = df.documentId
inner join tpl_fields TF on TF.id = df.fieldId and TF.fieldId = 135 AND df.calcValue = "13476148-0" -- 5$
) inner join tpl_fields TF on TF.id = df.fieldId and TF.fieldId = 143 AND JSON_VALID(df.calcValue)
inner join Template on Template.id = DA.templateId AND Template.TypeTemplate_id = 6 -- bordereau de livraison
CROSS JOIN JSON_TABLE(
JSON_UNQUOTE(df.calcValue), "$.header[*]"
COLUMNS(
cId INT path '$."globalColumnId"',
cName VARCHAR(256) PATH '$."name"')
) as jsh ON jsh.cId = 8
CROSS JOIN JSON_TABLE(
JSON_UNQUOTE(df.calcValue), "$.content[*]"
COLUMNS(
qteRecu VARCHAR(256) PATH "$.MY_DATE_HERE(jsh.cName)")
) as jsc
WHERE jsc.qteRecu != "" AND jsc.qteRecu IS NOT NULL;
我的 json,有一个 header,我在那里得到了键的名称,内容是我试图从键名中获取值的地方:
"header": [
{
"id": 1026,
"name": "No projet",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1226,
"y1": 627,
"x2": 1276,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-14 15:29:39",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": null,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 25,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1016,
"name": "No ligne",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 1,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1278,
"y1": 627,
"x2": 1328,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 1,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1017,
"name": "Article",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1330,
"y1": 627,
"x2": 1380,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 11,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1018,
"name": "Qte re\u00e7ue",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1382,
"y1": 627,
"x2": 1432,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 8,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1019,
"name": "Prix PO",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1434,
"y1": 627,
"x2": 1484,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 3,
"isDummy": 0,
"globalColumnId": 30,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1020,
"name": "Compte GL PO",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 117,
"height": 238,
"x1": 1486,
"y1": 627,
"x2": 1603,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 33,
"listDataId": null,
"zoneTolerence": null
}
],
"content": [
{
"No projet": "0",
"No ligne": 1,
"Article": "",
"Qte re\u00e7ue": "",
"Prix PO": 0,
"Compte GL PO": ""
},
{
"No projet": "15CALL",
"No ligne": 2,
"Article": "275019734",
"Qte re\u00e7ue": 1,
"Prix PO": 20,
"Compte GL PO": "570010;570010;110499"
},
{
"No projet": "15CALL",
"No ligne": 3,
"Article": "217041984",
"Qte re\u00e7ue": 1,
"Prix PO": 135,
"Compte GL PO": "570010;570010;110499"
},
{
"No projet": "0",
"No ligne": 4,
"Article": "",
"Qte re\u00e7ue": "",
"Prix PO": 0,
"Compte GL PO": ""
}
]
我认为这不可能。在加入其他表之前,必须修复 PATH。因此无法根据您加入的其他表中的值使 PATH 不同。
这类似于人们想要 的问题。 SQL 不支持。在查询开始读取任何数据行或计算表达式之前,表和列必须固定。
相反,我建议使用单独的路径公开所有内容字段,然后使用 CASE 表达式选择一个:
SELECT jsh.cName, CASE jsh.cName
WHEN 'No projet' THEN jsc.NoProjet
WHEN 'No ligne' THEN jsc.NoLigne
WHEN 'Article' THEN jsc.Article
...
END AS qteRecu
FROM ...
CROSS JOIN JSON_TABLE(
JSON_UNQUOTE(df.calcValue), "$.content[*]"
COLUMNS(
NoProjet VARCHAR(256) PATH '$."No projet"',
NoLigne INT PATH '$."No ligne"',
Article VARCHAR(256) PATH '$.Article',
QteRecu VARCHAR(256) PATH '$."Qte re\u00e7ue"',
...)
) as jsc
另一种方法是将您的内容构建为不同的 JSON 文档。
有没有办法将值或变量传递到 Mysql 中的 json_path?
我正在尝试使用 json_table 从我的 json 的 header 中获取值,然后从我得到的索引中获取内容中的日期。
在我下面的代码中,我试图传递值 jsh.cName
我的查询
Select jsh.cName, jsc.qteRecu from
DocumentField as df inner join DocumentAnchor DA on DA.currentDocId IN (
Select df.documentId from
DocumentField as df inner join DocumentAnchor DA on DA.currentDocId = df.documentId
inner join tpl_fields TF on TF.id = df.fieldId and TF.fieldId = 135 AND df.calcValue = "13476148-0" -- 5$
) inner join tpl_fields TF on TF.id = df.fieldId and TF.fieldId = 143 AND JSON_VALID(df.calcValue)
inner join Template on Template.id = DA.templateId AND Template.TypeTemplate_id = 6 -- bordereau de livraison
CROSS JOIN JSON_TABLE(
JSON_UNQUOTE(df.calcValue), "$.header[*]"
COLUMNS(
cId INT path '$."globalColumnId"',
cName VARCHAR(256) PATH '$."name"')
) as jsh ON jsh.cId = 8
CROSS JOIN JSON_TABLE(
JSON_UNQUOTE(df.calcValue), "$.content[*]"
COLUMNS(
qteRecu VARCHAR(256) PATH "$.MY_DATE_HERE(jsh.cName)")
) as jsc
WHERE jsc.qteRecu != "" AND jsc.qteRecu IS NOT NULL;
我的 json,有一个 header,我在那里得到了键的名称,内容是我试图从键名中获取值的地方:
"header": [
{
"id": 1026,
"name": "No projet",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1226,
"y1": 627,
"x2": 1276,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-14 15:29:39",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": null,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 25,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1016,
"name": "No ligne",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 1,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1278,
"y1": 627,
"x2": 1328,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 1,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1017,
"name": "Article",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1330,
"y1": 627,
"x2": 1380,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 11,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1018,
"name": "Qte re\u00e7ue",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1382,
"y1": 627,
"x2": 1432,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 8,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1019,
"name": "Prix PO",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1434,
"y1": 627,
"x2": 1484,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 3,
"isDummy": 0,
"globalColumnId": 30,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1020,
"name": "Compte GL PO",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 117,
"height": 238,
"x1": 1486,
"y1": 627,
"x2": 1603,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 33,
"listDataId": null,
"zoneTolerence": null
}
],
"content": [
{
"No projet": "0",
"No ligne": 1,
"Article": "",
"Qte re\u00e7ue": "",
"Prix PO": 0,
"Compte GL PO": ""
},
{
"No projet": "15CALL",
"No ligne": 2,
"Article": "275019734",
"Qte re\u00e7ue": 1,
"Prix PO": 20,
"Compte GL PO": "570010;570010;110499"
},
{
"No projet": "15CALL",
"No ligne": 3,
"Article": "217041984",
"Qte re\u00e7ue": 1,
"Prix PO": 135,
"Compte GL PO": "570010;570010;110499"
},
{
"No projet": "0",
"No ligne": 4,
"Article": "",
"Qte re\u00e7ue": "",
"Prix PO": 0,
"Compte GL PO": ""
}
]
我认为这不可能。在加入其他表之前,必须修复 PATH。因此无法根据您加入的其他表中的值使 PATH 不同。
这类似于人们想要
相反,我建议使用单独的路径公开所有内容字段,然后使用 CASE 表达式选择一个:
SELECT jsh.cName, CASE jsh.cName
WHEN 'No projet' THEN jsc.NoProjet
WHEN 'No ligne' THEN jsc.NoLigne
WHEN 'Article' THEN jsc.Article
...
END AS qteRecu
FROM ...
CROSS JOIN JSON_TABLE(
JSON_UNQUOTE(df.calcValue), "$.content[*]"
COLUMNS(
NoProjet VARCHAR(256) PATH '$."No projet"',
NoLigne INT PATH '$."No ligne"',
Article VARCHAR(256) PATH '$.Article',
QteRecu VARCHAR(256) PATH '$."Qte re\u00e7ue"',
...)
) as jsc
另一种方法是将您的内容构建为不同的 JSON 文档。