1. create a table named TEST 2. add data INSERTINTOTEST (STUDENT, COURSE, SCORE) to the TEST table select Zhang San, Chinese, Zhang San, mathematics, 87fromdualunionselect Zhang San, English, 82fromdualunionselect Zhang San, physics, 90 fromdualunio
1. create a table named TEST 2. add data insert into test (STUDENT, COURSE, SCORE) to the TEST table select 'zhang san', 'China', 78 from dual union select 'zhang san', 'mat ', 87 from dual union select 'zhang san', 'English ', 82 from dual union select 'zhang san', 'Physical', 90 from dual unio
1. Create a table named TEST
2. Add data to the TEST table
Insert into test (STUDENT, COURSE, SCORE)
Select 'zhang san', 'China', 78 from dual union
Select 'zhang san', 'mat', 87 from dual union
Select 'zhang san', 'English ', 82 from dual union
Select 'zhang san', 'Physical ', 90 from dual union
Select 'Li si', 'China', 65 from dual union
Select 'Li si', 'mat', 77 from dual union
Select 'Li si', 'English ', 65 from dual union
Select 'lily', 'Physical ', 85 from dual
The table data is as follows:
3. Column-to-row
Method · 1:
Select
Student,
Sum (decode (Course, 'mat', Score) mathematics,
Sum (decode (Course, 'Physical ', Score) physical,
Sum (decode (Course, 'English ', Score) English,
Sum (decode (Course, 'China', Score) Language
From
TEST
Group by Student
Method · 2:
Select
Student,
Sum (case Course when 'mate' then Score else null end) math,
Sum (case Course when 'physical 'then Score else null end) physical,
Sum (case Course when 'then Score else null end) English,
Sum (case Course when 'China' then Score else null end) Language
From
TEST
Group by Student
The effect is as follows:
Note: sum indicates the sum. For example, if there are two three records in the record, the result displayed in the column-to-row is the sum of the two three results.