Использование функций аналитики:
select cname, concat(pct, ' %') pct
from
(
select (
count(*) over (partition by cname)/
count(*) over ()
)*100 as pct,
cname
from (--Replace this subquery with your table
select stack (5,
1, 'Blue',
2, 'Green',
3, 'Green',
4, 'Blue',
5, 'Blue' ) as (id, cname)
) colors
)s
group by cname, pct;
Результат:
OK
Blue 60.0 %
Green 40.0 %
Просто замените подзапрос colors
таблицей