1 Create TableT_class2 (2Namevarchar2(255), 3Subjectvarchar2(255), 4Scoreinteger, 5Stuidinteger6 )7 8 Insert intoT_class2Values('Zhang San','Mathematics', the,1);9 Insert intoT_class2Values('Zhang San','language', the,1);Ten Insert intoT_class2Values('Zhang San','English', -,1); One A - Insert intoT_class2Values('John Doe','Mathematics', -,2); - Insert intoT_class2Values('John Doe','language', -,2); the Insert intoT_class2Values('John Doe','English', the,2); - - Select * fromT_class2 - + - --calculate each person's total and rank desc descending sort sum () aggregate function + SelectNamesum(score) Sumscore fromT_class2Group byNameOrder bySumscoredesc A at - --calculate average results for each person AVG () aggregate function averaging - SelectNameavg(score) Avgscore fromT_class2Group byname - - - --calculate the max () aggregation function for each person's single highest score to find the maximum value in SelectNameMax(score) Maxscore fromT_class2Group byname - to + --list the students with the best grades in each section - the SelectC2.name, C2.subject,c2.score fromT_class2 C2, *(SelectSubjectMax(score) Maxscore fromT_class2Group bysubject) C1 $ whereC2.subject=C1.subject andC2.score=C1.maxscore
Aggregate functions in Oracle Statements and usages of grouped group by