Horizontal Table Conversion Vertical table:
CREATE Table score (username varchar (ten), Chinese int, math int, physics int); INSERT into score (username , Chinese, math, physics) VALUES (' Kay ', 74,83,93), INSERT into score (username, Chinese, math, physics) VALUES (' Jim ', 75, 84,94); INSERT into score (username, Chinese, math, physics) VALUES (' Lily ', 86,49,91); COMMIT; SELECT * from score;
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/59/2A/wKioL1TJmWTDimcKAABhyIsoWbg511.jpg "title=" score. PNG "alt=" Wkiol1tjmwtdimckaabhyisowbg511.jpg "/>
The key to converting a horizontal table to a vertical table is how to convert a record into multiple records, three sub-fields corresponding to three records, a single record with only three records in the intermediate table and a score table as a Cartesian product to copy a record into three records
With T as (select ' Chinese ' course from dual UNION ALL select ' Math ' course from dual UNION all select ' Physics ' C Ourse from dual) SELECT Username,course,decode (course, ' Chinese ', Chinese, ' math ', Math, ' physics ', physics) from score, T O Rder by username, course;
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/2D/wKiom1TJmVmAwnwpAADqXvmhWJg275.jpg "title=" T.png " alt= "Wkiom1tjmvmawnwpaadqxvmhwjg275.jpg"/>
This article from the "Down-to-earth, look at the Stars" blog, please be sure to keep this source http://xubcing.blog.51cto.com/3502962/1609478
SQL Scale Table Conversion