给定下面的示例 json 数据,我如何编写一个查询来一步提取数组数据?我的目标是为 ActionRecs 数组 (4) 中的每个项目保留一行。我的实际 json 更复杂,但我认为这很好地说明了我的目标。
declare @json2 nvarchar(max)
set @json2 = '{
"RequestId": "1",
"ActionRecs": [
{
"Type": "Submit",
"Employee": "Joe"
},
{
"Type": "Review",
"Employee": "Betty"
},
{
"Type": "Approve",
"Employee": "Sam"
},
{
"Type": "Approve",
"Employee": "Bill"
}
]
}'
SELECT x.*
, JSON_QUERY(@json2, '$.ActionRecs') as ActionArray
from OPENJSON(@json2)
with (Id varchar(5) '$.RequestId') as x