这是我的表[类型]
这是我的表[Value]
我的sql脚本是
SELECT T.TypeId, V.ValueId
FROM [dbo].[Type] AS T
INNER JOIN [dbo].[Value] AS V ON V.[TypeId] = T.[TypeId]
FOR JSON PATH
它会得到结果
[
{
"TypeId":"TypeId_1",
"ValueId":"ValueId_1"
},
{
"TypeId":"TypeId_1",
"ValueId":"ValueId_2"
},
{
"TypeId":"TypeId_1",
"ValueId":"ValueId_3"
},
{
"TypeId":"TypeId_2",
"ValueId":"ValueId_4"
},
{
"TypeId":"TypeId_2",
"ValueId":"ValueId_5"
}
]
但是我想让TypeId作为json属性名,它的值是ValueId的数组,如:
{
"TypeId_1": [
"ValueId_1",
"ValueId_2",
"ValueId_3"
],
"TypeId_2": [
"ValueId_4",
"ValueId_5"
]
}
如何调整我的sql脚本?