在mysql中,我們可以使用一些簡單的sql語句來計算成績的分布律。下面是一些示例代碼:
-- 計算成績總數 SELECT COUNT(*) FROM score; -- 計算成績總和 SELECT SUM(score) FROM score; -- 計算平均分 SELECT AVG(score) FROM score; -- 計算最高分 SELECT MAX(score) FROM score; -- 計算最低分 SELECT MIN(score) FROM score; -- 計算各個成績段的人數和比例 SELECT '60-69' AS `range`, COUNT(*) AS `count`, CONCAT(ROUND(COUNT(*)/(SELECT COUNT(*) FROM score), 4)*100, '%') AS `percent` FROM score WHERE score>=60 AND score<=69 UNION ALL SELECT '70-79' AS `range`, COUNT(*) AS `count`, CONCAT(ROUND(COUNT(*)/(SELECT COUNT(*) FROM score), 4)*100, '%') AS `percent` FROM score WHERE score>=70 AND score<=79 UNION ALL SELECT '80-89' AS `range`, COUNT(*) AS `count`, CONCAT(ROUND(COUNT(*)/(SELECT COUNT(*) FROM score), 4)*100, '%') AS `percent` FROM score WHERE score>=80 AND score<=89 UNION ALL SELECT '90-100' AS `range`, COUNT(*) AS `count`, CONCAT(ROUND(COUNT(*)/(SELECT COUNT(*) FROM score), 4)*100, '%') AS `percent` FROM score WHERE score>=90 AND score<=100;
以上代碼分別計算了成績的總數、總和、平均分、最高分、最低分以及各個成績段的人數和比例。我們可以根據這些數據進一步分析學生的成績分布情況,為學生提供更好的學習建議。
上一篇mysql怎么篩選列
下一篇css構成三要素