原始 数据表为:
宿舍 成绩
1102 A
1103 B
1104 B
1105 C
1102 B
1103 B
1104 C
1105 A
1103 C
1104 A
1103 A
成绩栏共分三个档次即ABC,怎样才能利用查询分别计算出各宿舍ABC的的百分率呢,谢谢!!!如果没有的就用0来表示:
宿舍 A B C
1102 23% 77% 0%
1103 0% 40% 60%
.
.
.
请各位高手帮忙!谢谢[em06]
select distinct test.宿舍,Na / nt ,nb / nt,nc / nt
from (select 宿舍,count(宿舍) as NA from test where 成绩='a' group by 宿舍) as ta right join ((select 宿舍,count(宿舍) as NB from test where 成绩='b' group by 宿舍) as tb right join ((select 宿舍,count(宿舍) as NC from test where 成绩='c' group by 宿舍) as tc right join ((select 宿舍,count(宿舍) as nt from test group by 宿舍) as tt right join test on tt.宿舍=test.宿舍) on tc.宿舍=test.宿舍) on tb.宿舍=test.宿舍 ) on ta.宿舍=test.宿舍