- The most efficient (using over()).
select Grade, count(*) * 100.0 / sum(count(*)) over() from MyTablegroup by Grade
- Universal (any SQL version).
select Rate, count(*) * 100.0 / (select count(*) from MyTable) from MyTablegroup by Rate;
- With CTE, the least efficient.
with t(Rate, RateCount) as ( select Rate, count(*) from MyTable group by Rate) select Rate, RateCount * 100.0/(select sum(RateCount) from t) from t;
No comments:
Post a Comment