mysql score如何進(jìn)行統(tǒng)計(jì)分析

小樊
84
2024-09-06 15:14:37
欄目: 云計(jì)算

在MySQL中,可以使用聚合函數(shù)和GROUP BY子句對(duì)成績(jī)(score)進(jìn)行統(tǒng)計(jì)分析。以下是一些常見的統(tǒng)計(jì)分析方法:

  1. 計(jì)算平均分:
SELECT AVG(score) as average_score FROM your_table;
  1. 計(jì)算最高分和最低分:
SELECT MIN(score) as min_score, MAX(score) as max_score FROM your_table;
  1. 計(jì)算總分:
SELECT SUM(score) as total_score FROM your_table;
  1. 按照分?jǐn)?shù)范圍進(jìn)行分組統(tǒng)計(jì):
SELECT 
    CASE
        WHEN score BETWEEN 0 AND 59 THEN '0-59'
        WHEN score BETWEEN 60 AND 79 THEN '60-79'
        WHEN score BETWEEN 80 AND 99 THEN '80-99'
        ELSE '100'
    END as score_range,
    COUNT(*) as count
FROM your_table
GROUP BY score_range;
  1. 按照某個(gè)字段(例如:class)進(jìn)行分組統(tǒng)計(jì):
SELECT class, AVG(score) as average_score, MIN(score) as min_score, MAX(score) as max_score
FROM your_table
GROUP BY class;

請(qǐng)將your_table替換為你的表名,并根據(jù)需要調(diào)整查詢語句。

0