Clever Use of the Oracle analysis function row_number ()

Source: Internet
Author: User
  • Winmenaruto
  • (Pangpang)
  • Level 1:
  • Post completion rate:97.96%
Published on: 14:03:02
The student table has three columns: name, course, and score.
Name curricula mark
Zhang San Language 70
Li Si math 80
Dynasty English 59
Manzhe 70
Dynasty Chinese 90
...........

What I want to achieve is to list the names of passing subjects:
Chinese chemistry and mathematics
Zhang San, Li Si
Dynasty

How can this problem be solved? There are more than three subjects, and there may be an issue. I will skip it later.

 

 

SQL code
  -- Test data: Name curricula mark Zhang San Language 70 Li Si mathematics 80 Dynasty English 59 City South Ma Zhe 70 Dynasty Chinese 90 -- SQL: Select Sn, max (case when curricula = 'China' then name end) language, max (case when curricula = 'mate' then name end) mathematics, max (case when curricula = 'English 'Then name end) English, max (case when curricula = 'mazel' then name end) Ma Zhe from (Select name, curricula, mark, row_number () over (partition by curricula order by name) Sn from t where Mark> 59) group by Sn -- result: Ma Zhe 1 Zhang San Li Si Chengnan 2 Dynasty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.