2 Categories of MySQL

Source: Internet
Author: User

1, will the following table in each of the results are more than 80 points of the name?

Tom Chinese 81
Tom Mathematical 75
John doe Chinese 76
John doe Mathematical 90
Harry Chinese 81
Harry Mathematical 100
Harry English 90

SELECT * from TB_STU2;
Select distinct stu2_name from TB_STU2 where Stu2_name not in
(select distinct stu2_name from TB_STU2 where stu2_score<80);

2. Output the information of the older son of the father?

CREATE TABLE Student (
stu_id int,
Stu_age int,
Stu_name varchar (30),
Stu_f int
);
Create TABLE Father (
c_id int,
C_master varchar (30)
);
INSERT into student values (1, 28, ' constructed ', 1);
INSERT into student values (2,20, ' Harry ', 1);
INSERT into student values (3,24, ' Li Ka ', 2);
INSERT into student values (4,25, ' Li Zehou ', 2);

Insert into Father values (1, ' Wang Jianlin ');
Insert into Father values (2, ' Li Ka-shing ');


#先建立父亲对儿子的一对多的关系, and then elect the respective older sons to show:
SELECT * FROM student join Father in student.stu_f=father.c_id where (student.stu_age= (select Max (stu_age) from student WH ere stu_f=1))
or (student.stu_age= (select Max (stu_age) from student where stu_f=2));

2 Categories of MySQL

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.