The basic idea of converting a horizontal table to a vertical table is:
1) The horizontal table of multiple data, "pressure" into one. The equivalent of grouping so many, each group "presses" into one piece of data. Using GROUP BY
2) The columns in the vertical table are populated with the data for a particular row, using the value end that is not used in case of ' a ' then ' B ' else, in order to filter some unused data, the commonly used function has Max (), SUM ()
PS: If there is no aggregation function handsome election. The database will return the first data to you, basically just you fill out "No use value"
Here is an example:
SELECTNAME,MAX( CaseSUBJECT when 'language' ThenResultELSE 0 END) languages,MAX( CaseSUBJECT when 'Mathematics' ThenResultELSE 0 END) Mathematics,MAX( CaseSUBJECT when 'Physical' ThenResultELSE 0 END) Physical fromTBGROUP by' Name '
Get the result is
SQL writes a table-and-chart conversion