Concepts of banner and general tables

Source: Internet
Author: User

Now the conversion method is listed as follows:

1, the longitudinal table to the horizontal table:

TableA structure of the longitudinal table

Name

Course

Grade

Tom

Chinese

75

Tom

Mathematical

80

Tom

English

90

John doe

Chinese

95

John doe

Mathematical

55

Horizontal table Structure TableB

Name

Chinese

Mathematical

English

Tom

75

80

90

John doe

95

55

0

Method One:

Select Name,

SUM (case Course "language" then Grade else 0 end) as language,

SUM (case Course when ' math ' then Grade else 0 end) as mathematics,

SUM (case Course when ' English ' then Grade else 0 end) as English

From TableA

GROUP BY Name

2. "SQL" example of horizontal table to table
Horizontal table structure: test_h2z
ID name Chinese Math english
1 Sheets 380 90 70
2 Lee 490 85 95
3 Wang 588 75 90

The converted table structure:
ID Name Account Score
1 in three languages 80
2 Zhang Three Mathematics 90
3 three English 70
4 John Doe Language 90
5 John Doe Mathematics 80
6 John Doe English 99
7 Harry Language 85
8 Harry Mathematics 96
9 Harry English 88
Table of horizontal Tables SQL example:
SELECT name, ' language ' as subject, language as score from test_h2z UNION all
SELECT name, ' Math ' as subject, math as score from test_h2z UNION all
SELECT name, ' English ' as subject, English as score from test_h2z
ORDER by name, subject DESC;

Concepts of banner and general tables

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.