Reputation: 8765
I have the following table:
that contains these data:
How can I group by my array items in my JSON Column? and get this result:
Upvotes: 3
Views: 1120
Reputation: 1959
If you cannot use OPENJSON, here is an alternative
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
Upvotes: 1