SQL question _ MySQL

Source: Internet
Author: User
SQL questions encountered in the interview questions bitsCN.com

1. suppose there is a sheet indicating cj table Name Subject Result Zhang San language 80 Zhang San mathematics 90 Zhang San Physics 85 Li Si language 85 Li Si Mathematics 92 Li Si physics 82 requirement query Result: name Chinese mathematics physics Zhang San 80 90 85 Li Si 85 92 82
1 -- CREATE cj TABLE sql2 create table 'CJ '(3 'id' int (11) not null AUTO_INCREMENT, 4 'name' varchar (20) default null, 5 'subobject' varchar (20) default null, 6 'result' int (11) default null, 7 primary key ('id') 8) ENGINE = InnoDB AUTO_INCREMENT = 7 default charset = utf8;
1 -- INSERT data SQL 2 INSERT INTO cj 3 ('id', 'name', 'subobject', 'result') 4 VALUES 5 (1, 'Zhang San ', 'China', 80); 6 7 insert into cj 8 ('id', 'name', 'subobject', 'result') 9 VALUES10 (2, 'Zhang San ', 'mat', 90); 11 12 insert into cj13 ('id', 'name', 'subobject', 'result') 14 VALUES15 (3, 'Zhang San ', 'Physical ', 85); 16 17 insert into cj18 ('id', 'name', 'subobject', 'result') 19 VALUES20 (4, 'Lily ', 'China', 85); 21 22 insert into cj23 ('id', 'name', 'subobject', 'result') 24 VALUES25 (5, 'Lily ', 'mat', 92); 26 27 insert into cj28 ('id', 'name', 'subobject', 'result') 29 VALUES30 (6, 'Lily ', 'Physical ', 89 );
1 -- query SQL2 select 3 distinct. name, 4 (select result from cj where name =. name and subject = 'China') language, 5 (select result from cj where name =. name and subject = 'mate') Mathematics, 6 (select result from cj where name =. name and subject = 'Physical ') physical 7 from cj;

BitsCN.com

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.