Table1 有 两 列,分别记录名字和成绩,现在要GroupBy 【名字】,并且显示 【成绩个数】【最高分】【最低分】【平均分】
比如下面的例子:
Name; Score
Zhao; 70
Qian; 60
Sun; 50
Zhao; 50
Zhao; 50
Qian; 30
Sun; 50
Li; 90
查询结果应该是:
Name; NoOfScores; Max_Score; Min_Score; Avg_Score;
Zhao; 3; 70; 50; 56.66
Qian; 2; 60; 30; 45
Sun; 2; 50; 50; 50
Li; 1; 90; 90; 90
------解决思路----------------------
SELECT Name
,COUNT(1) NoOfScores
,MAX(Score)Max_Score
,MIN(Score)Min_Score
,ROUND(AVG(CAST(Score AS DECIMAL(18,2))),2,1)Avg_Score
FROM Table1
GROUP BY Name
------解决思路----------------------
????,ROUND(AVG(CAST(Score?AS?DECIMAL(18,2))),2,1)Avg_Score
-- 可以改成
????,ROUND(AVG(CAST(Score?* 1.0)),2,1)Avg_Score