-
最も効率的(over()を使用)。
select Grade, count(*) * 100.0 / sum(count(*)) over() from MyTable group by Grade
-
ユニバーサル(任意のSQLバージョン)。
select Grade, count(*) * 100.0 / (select count(*) from MyTable) from MyTable group by Grade;
-
CTEを使用すると、効率が最も低くなります。
with t(Grade, GradeCount) as ( select Grade, count(*) from MyTable group by Grade ) select Grade, GradeCount * 100.0/(select sum(GradeCount) from t) from t;