oracle語句中的彙總函式以及分組group by的使用執行個體

來源:互聯網
上載者:User

標籤:arc   rom   insert   AC   where   英語   group by   ora   sel   

 

 1 create table t_class2( 2   name varchar2(255),  3   subject varchar2(255),  4   score integer,  5   stuid integer 6 ) 7  8 insert into t_class2 values(‘張三‘,‘數學‘,89,1); 9 insert into t_class2 values(‘張三‘,‘語文‘,80,1);10 insert into t_class2 values(‘張三‘,‘英語‘,70,1);11 12 13 insert into t_class2 values(‘李四‘,‘數學‘,90,2);14 insert into t_class2 values(‘李四‘,‘語文‘,70,2);15 insert into t_class2 values(‘李四‘,‘英語‘,80,2);16 17 select * from t_class218 19 20 --計算每個人的總成績並排名  desc降序排列  sum()彙總函式求總21 select name, sum(score) sumscore  from t_class2 group by name order by sumscore desc22 23 24 --計算每一個人的平均成績 avg()彙總函式求平均值25 select name, avg(score) avgscore  from t_class2 group by name26 27 28 --計算每個人的單科最高成績 max()彙總函式求最大值29 select name,max(score) maxscore from t_class2 group by name30 31 32 --列出每一科成績最好的學生33 34 select c2.name, c2.subject,c2.score from t_class2 c2  ,35 ( select subject,  max(score) maxscore from t_class2 group by subject) c136 where c2.subject=c1.subject and c2.score=c1.maxscore

 

oracle語句中的彙總函式以及分組group by的使用執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.