Oracle row columns (multiple rows into one line/multiple lines merged into multiple columns/merged rows) ____oracle

Source: Internet
Author: User
Tags mysql in

And MySQL in contrast to see: http://blog.csdn.net/rainyspring4540/article/details/50231435

This is the oracle10g environment.

The database structure is as follows:


If I want to show the same name on the same line, there are 2 basic shows:

First presentation (displayed on different columns of the same row)

Its SQL is as follows:

Select Name,
max (decode (type, ' math ', score,0) as math,
max (decode (type, ' 中文版 ', score,0)) as English,
Max ( Decode (Type, ' Chinese ', score,0)) as language from
stu2
GROUP by name
Because a person here only corresponds to a subject's score, all you use Max and sum is the same, if a person has multiple grades in one subject, then sum is the meaning of summation, and Max is to take the maximum, I will not write cases, their own attention to OK


Second show (shown on the same column in the same row)

SQL is as follows:

Select Name,
max (decode (type, ' math ', score,0)) |
| Max (decode (type, ' 中文版 ', score,0)) |
| | Max (decode (type, ' Chinese ', score,0)) as Allscore from
stu2
GROUP by name
If you are familiar with string stitching | | Use to make more styles:

Style 1:


Related Article

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.