Today, qq friends have a buddy who is in an interview and has a column-and-column conversion question. At that time, he was a bit blind. When he came back, he looked at some people in the group and shared them together.
Result:
After reading this, I know that this is a standard conversion problem. To be honest, I just know that I have never studied it carefully.
Write a simple
Code
Declare @ table
(
ID int,
Course varchar (10 ),
Point int
)
Insert into @ table
Select 1, 'China', 87
Union all
Select 1, 'mat', 98
Union all
Select 2, 'China', 54
Union all
Select 3, 'China', 97
Union all
Select 3, 'mat', 92
Union all
Select 4, 'mat', 86
Union all
Select 5, 'mat', 65
Union all
Select 6, 'China', 76
Select ID
, Max (case when course = 'mate' then Point else 0 end) as 'mate'
, Max (case when course = 'China' then Point else 0 end) as 'China'
From @ table group by ID
This can solve the above problems simply. However, the problem arises. I now know that it is a two-Course: 'mat' and 'China.
What if I don't know how many courses there are? (To be continued)