First, you should not store lists of things in a line.
But sometimes one is stuck in this format. In your example, you seem to have a table with all possible values. If so, you can use join:
select e.col1, count(e2.col2)
from example e left join
example e2
on charindex(e.col1, e2.col2) > 0
group by e.col1;
Note. In this case, the rows containing the value are counted. If multiple values ββappear on the same line, the query is a bit more complicated.
source
share