MySQL Query small demo

Source: Internet
Author: User
Tags mysql query one table

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.