巧用ORACLE中的分析函數row_number()

來源:互聯網
上載者:User
  • winmenaruto
  • (pangpang)
  • 等 級:
  • 結帖率:97.96%
樓主發表於:2009-08-05 14:03:02
Student表有三列,分別是姓名、課程、成績
Name  Curricula    Mark
張三    語文        70
李四    數學        80
王朝    英語        59
城南    馬哲        70
王朝    語文        90
。。。。。。。。。。。

我想得到的效果是,列出各個學科及格的人名:
語文    化學    數學
張三            李四
王朝

怎麼弄呢?學科不止3門,可能有八門,後面都省略不寫了   

 

 

     

SQL code
--TEST DATA:Name  Curricula    Mark 張三    語文        70 李四    數學        80 王朝    英語        59 城南    馬哲        70 王朝    語文        90 --SQL:select sn,max(case when Curricula='語文' then name end)  語文,max(case when Curricula='數學' then name end)  數學,max(case when Curricula='英語' then name end)  英語,max(case when Curricula='馬哲' then name end)  馬哲from (    select name,curricula,mark,    row_number() over(partition by curricula order by name) sn    from t where mark>59)group by sn--RESULT:        語文     數學      英語    馬哲1      張三    李四               城南2     王朝            

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.