My problem is that I have a table with data like this –
ID COLORS
--------------------------------------------
1 ["red", "green"]
2 ["blue", "red"]
3 ["red", "green", "yellow", "blue"]
What SQL witchcraft will I need to wield in order to create a result like that? –
COLOR COUNT
--------------------------------------------
red 3
blue 2
green 2
yellow 1
Is it even possible with either a SP or View?
Thank you!
2
Answers
You can flatten the arrays by using
cross join
and then applycount(*)
:See fiddle.