0

Input:

col1
a,b
a,c

Output:

col1   count
a      2
b      1
c      1

I want to simply count multivalue rows in MySQL Query.

lil-wolf
  • 372
  • 2
  • 15

1 Answers1

0

If your "table" is a large table or view, then you can use cross join to generate the rows with only one table reference:

select (case when n.n = 1 then col1 else col2 end) as col,
       count(*)
from t cross join
     (select 1 as n union all select 2) n
group by col;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786