consider you have a table as below
Select min(subset.g), count(subset.val)
from
(
Select 'c1 & '+cast(Val1 as varchar(4)) as G,
val1 as val
from test
Union all
Select 'c2 & '+ cast(Val2 as varchar(4)) as G,
val2 as val
from test
Union all
Select 'c3 & '+ cast(Val3 as varchar(4)) as G,
val3 as val
from test
) as subset
Group by Left(subset.g,2),subset.val
Order by Left(subset.g,2)
the the result set would be like this