2

我有一个表[JsonTable],列[JsonData]保存json字符串,

JsonData 喜欢:

{
   "Content": [
      {
         "ContentId": "123",
         "Type": 1
      },
      {
         "ContentId": "456",
         "Type": 2
      }
   ]
}

或者

[
     {
        "ContentId": "123",
        "Type": 1
     },
     {
        "ContentId": "456",
        "Type": 2
     }
]

我怎样才能像内部一样加入

SELECT* FROM [Content] AS C
INNER JOIN [JsonTable] AS J ON C.[Id] IN (SELECT value FROM OPENJSON(J.[JsonData],'$.Content.ContentId'))
4

1 回答 1

1

您可以使用此查询。

SELECT * FROM [Content] AS C
INNER JOIN [JsonTable] AS J ON C.[Id] IN (SELECT JSON_VALUE(value,'$.ContentId') 
                                          FROM OPENJSON(J.[JsonData],'$.Content'))
于 2017-10-31T19:37:59.487 回答