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