CREATE table t_group( id int(11) ,name varchar(50));
alter table t_group add primary key (id);
create table t_score( id int(11), g_id int(11), score int(11));
alter table t_score add primary key (id);
insert into t_group (id, name) values ('1', 'a');
insert into t_group (id, name) values ('2', 'b');
insert into t_group (id, name) values ('3', 'c');
insert into t_group (id, name) values ('4', 'd');
insert into t_group (id, name) values ('5', 'e');
insert into t_score (id,g_id, score) values ('1','1', '81');
insert into t_score (id,g_id, score) values ('2','1', '73');
insert into t_score (id,g_id, score) values ('3','2', '78');
insert into t_score (id,g_id, score) values ('4','3', '92');
select tg.name , sum(ts1.score) / (select sum(ts.score) from t_score ts) * 100 as perc
from t_score ts1 join t_group tg on ts1.g_id = tg.id
group by tg.name
select tg.name, sum(ts.score)* 100 /(select sum(ts1.score)from t_score ts1) as c
from t_group tg join t_score ts on tg.id = ts.g_id
group by tg.name order by c DESC ;