The structure of the two tables is as follows: The requirement is to write the query transformation from one table to the other table and from the second table to the one table.
CREATE TABLE Student_one (name varchar () default ' not Null,type varchar (TEN) NOT null default 0,score float (5,2) not nul L default 0.00) engine=innodb;create table Student_two (name varchar () default ' not Null,math float (5,2) not null de Fault 0.00,english float (5,2) NOT null default 0.00,chinese float (5,2) NOT NULL default 0.00) Engine=innodb;
The current table shows the following data
The statement for table one is based on table one in the following format:
Select A.name,a.score as ' Math ', b.score as ' Chinese ', c.score as ' 中文版 ' from Student_one a join Student_one b join Studen T_one C on A.name=b.name and A.name=c.name and b.name=c.name where a.type= ' math ' and b.type= ' Chinese ' and c.type= ' Engine ';
The query results are as follows:
The statements in table one are identified in table one as follows:
Select A.name,a.math as score, ' math ' as type from Student_two a unionselect b.name,b.english as score, ' 中文版 ' as type fr Om student_two b unionselect c.name,c.chinese as score, ' Chinese ' as type from student_two C;
The query results are as follows:
MySQL Query small demo