我的一個表在一列的每一行中都包含 JSON 值。
資料如下(示例。一行)
[{"id":"30a66bec-c0aa-4655-a8ef-506e52bfcc14","type":"nps","value":"promoter","decimalValue":"10"},{"id":"37850b3b-1eac-4921-ae22-b2f6d2450897","type":"sentiment","value":"positive","decimalValue":"0.990000009536743"}]
現在我正在嘗試從中檢索兩列。(標識,值)
我正在撰寫以下查詢,但在新列的每一行中JSON_VALUE獲取值。NULL
select a.jsondata,JSON_VALUE(a.jsondata,'$.id') from table as a
uj5u.com熱心網友回復:
您的 JSON 欄位是一個陣列,因此您需要指定要使用的元素,假設它始終是您可以使用的第一個元素:
select a.jsondata,JSON_VALUE(a.jsondata,'$[0].id') from table as a
您需要更改方括號內的索引才能從 JSON 字串中訪問所需的 id
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/463016.html
標籤:sql json sql服务器 sql-server-2016
上一篇:php中的json多重選擇器
