1. Create a table and prepare the next data source
1 Create TableStudent2 (3Idint Primary Key Identity(1,1) not NULL,4Stunamenvarchar( -),5Coursenamenvarchar( -),6Scoreint,7CreatetimeDateTime 8 9 )Ten One Insert intoStudentValues('Zhang San','language',Bayi,GETDATE()) A Insert intoStudentValues('Zhang San','Mathematics', the,GETDATE()) - Insert intoStudentValues('Zhang San','English', the,GETDATE()) - Insert intoStudentValues('John Doe','language', the,GETDATE()) the Insert intoStudentValues('John Doe','Mathematics', the,GETDATE()) - Insert intoStudentValues('John Doe','English', the,GETDATE())
2. When a case is implemented
1 SelectStuname,2 Max( CaseCoursename when 'language' ThenScoreEnd) as 'language',3 Max( CaseCoursename when 'Mathematics' ThenScoreEnd) as 'Mathematics',4 Max( CaseCoursename when 'English' ThenScoreEnd) as 'English'5 fromStudentGroup byStuname
3. Using the pivot function provided by Microsoft
SelectStuname,[language],[Mathematics],[English] from ( SelectStuname,score,coursename fromStudent) asPpivot (sum(score) forCoursenameinch([language],[Mathematics],[English])) T
4. Record a function that adds a number of thousand characters to a digit
SELECT ' 111111111 ' as CONVERT (VARCHAR(+),CAST(CONVERT(DECIMAL(2) ,LTRIM(111111111as Money),1) dollar--lirim (field name)
SQL Row to Column