目前我仍然坚持如何从JSON中选择一个值。
表广告资源:
Name | Json_Column
-------+--------------------------------------------------------------------
Ball | [{"skuId":"1","quantity":1,"skuName":"$5 valley ball"},{"skuId":"2","quantity":1,"skuName":"$10 BasketBall"}]
Racket | [{"skuId":"3","quantity":1,"skuName":"$5 Badminton racket"}]
我想使用select SQL语句将以下结果转换为:
Name | Json_Column
-------+---------------------------------------
Ball | $5 valley ball, $10 BasketBall
Racket | $5 Badminton racket
当我使用此SQL语句进行选择时,它返回null;我需要一些SQL帮助。
select JSON_VALUE (Json_Column, '$.skuName') as Name
from Inventory
答案 0 :(得分:1)
尝试使用OPENJSON
SELECT * FROM OPENJSON(Json_Column, '$')
WITH (skuId int'$.skuId',quantity int '$.quantity',skuName varchar(50) '$.skuName')
<强>更新强>
好的,所以从表中选择你可以用OPENJSON交叉申请
SELECT skuName from Inventory
CROSS APPLY
OPENJSON (Json_Column)
WITH (skuId int'$.skuId',quantity int '$.quantity',skuName varchar(50) '$.skuName')