我们将 JSON 数据存储在 Azure CosmosDB 容器中,如下所示:
[
{
"WebId": "99999996_2_10_125064",
"SectionId": 1551,
"rowtype": 4,
"Fields": [
{
"FieldId": 8998,
"FieldValue": "1002100481",
"FieldName": "<p>Project_No</p>8998"
},
{
"FieldId": 9839,
"FieldValue": "Customer Name 123",
"FieldName": "<p>Customer_Name</p>9839"
}
]
},
{
"WebId": "99999996_2_10_125064",
"SectionId": 1552,
"rowtype": 4,
"Fields": [
{
"FieldId": 13362,
"FieldValue": "76215_1_9_122345",
"FieldName": "<p>LW_WebID</p>13362"
},
{
"FieldId": 10369,
"FieldValue": null,
"FieldName": "<p>TRM_ID</p>10369"
}
]
}
],
[
{
"WebId": "99999996_2_10_125070",
"SectionId": 1551,
"rowtype": 4,
"Fields": [
{
"FieldId": 8998,
"FieldValue": "1002100482",
"FieldName": "<p>Project_No</p>8998"
},
{
"FieldId": 9839,
"FieldValue": "Customer Name 124",
"FieldName": "<p>Customer_Name</p>9839"
}
]
},
{
"WebId": "99999996_2_10_125070",
"SectionId": 1552,
"rowtype": 4,
"Fields": [
{
"FieldId": 13362,
"FieldValue": "94215_1_9_122346",
"FieldName": "<p>LW_WebID</p>13362"
},
{
"FieldId": 10369,
"FieldValue": null,
"FieldName": "<p>TRM_ID</p>10369"
}
]
}
]
是否有可能获得所有
WebIDs
,其中FieldValue
的Fields.FieldName = <p>LW_WebID</p>13362
是Fields.FieldValue LIKE '76215_1_9_%'
?从样本数据来看,它应该只获取来自WebId = '99999996_2_10_125064'
的记录。
目前,我们只能提取具有
Field.FieldId
值 8998, 9839, 13362 and 10369
的所有记录,如下所示。之后,我们在 Power Query 中旋转数据并过滤LW_WebId
,但是是否可以直接通过本机查询过滤数据?
SELECT
c["WebId"]
, c["SectionId"]
, c["rowtype"]
, d["FieldId"]
, d["FieldName"]
, d["FieldValue"]
FROM c
JOIN d IN c["Fields"]
WHERE
c["WebId"] LIKE '99999996_2_10_%'
d["FieldId"] IN (13362, 8998, 9839)
尝试使用以下查询,它会通过以下相应条件获取带有
WebId = '99999996_2_10_125064'
的记录,如下所示:
SELECT
c["WebId"]
, c["SectionId"]
, c["rowtype"]
, d["FieldId"]
, d["FieldName"]
, d["FieldValue"]
FROM c
JOIN d IN c["Fields"]
WHERE
c["WebId"] LIKE '99999996_2_10_%'
AND (
d["FieldName"] = '<p>LW_WebID</p>13362' AND STARTSWITH(d["FieldValue"], '76215_1_9_')
)
输出:
[
{
"WebId": "99999996_2_10_125064",
"SectionId": 1552,
"rowtype": 4,
"FieldId": 13362,
"FieldName": "<p>LW_WebID</p>13362",
"FieldValue": "76215_1_9_122345"
}
]