答案 0 :(得分:1)
您可以尝试将OPENJSON与CROSS APPLY
结合使用。
SELECT
col1,
UserID
FROM T t1
CROSS APPLY
OPENJSON(t1.Roles)
WITH
(
col1 varchar(50) N'$'
) AS a
答案 1 :(得分:1)
如果您不能使用OPENJSON,则可以选择
Select
aRole, COUNT(*) as cnt
From (
Select
a.ID
,b.Items as aRole
From
(Select *
,replace(replace(replace(Roles,'[',''),']',''),'"','') as Rolesx
From JSONgroup) a
Cross Apply dbo.Split(a.Rolesx, ',') b
) c
group by aRole