MySQL row variable column (multiple rows become one row/multiple rows merged into one row/multiple rows merged into multiple columns/merged rows)

Source: Internet
Author: User

Database structure

And I want to make the same person's different grades into this person. displayed on different columns of this line, this time divided into 2 shows:

The first shows----"Multiple rows to one column" (the merged data is on the same column):

SQL is as follows:

The second shows----"Multiline multiple Columns" (the merged data is on different columns):

SQL is as follows:

SELECT name, MAX (case type when ' math ' then score else 0 end) Math,max (case Type "English" then score else 0 end) 中文版 , MAX (case Type "language" then score ELSE 0 END) Chinese from Stu  GROUP by name

-----------------------------------------------------------------------------------------------------Cute Split-line-------------- --------------------------------------------------------------------------------------

Of course, in the first case (shown in a column), there are some other similar forms:

Form one:

SQL is as follows:

Select Name, Group_concat (type, ' fractions: ', score  


Hehe, of course, if you are familiar with the usage of Group_concat and concat, you also make the following form:

Its SQL is as follows:

Select Name, concat (name, ' The score is [', Group_concat (type, ' fraction: ', score  

MySQL row variable column (multiple rows become one row/multiple rows merged into one row/multiple rows merged into multiple columns/merged rows)

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.