1、將如下表中的每門成績都大於80分的人名?
張三 語文 81 張三 數學 75 李四 語文 76 李四 數學 90 王五 語文 81 王五 數學 100 王五 英語 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、輸出老爹對應的大兒子的信息?
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,'王思聰',1);
insert into student values(2,20,'王五',1);
insert into student values(3,24,'李嘉',2);
insert into student values(4,25,'李澤',2);
insert into father values(1,'王健林');
insert into father values(2,'李嘉誠');
#先建立父親對兒子的一對多的關系,然後選出各自的大兒子顯示:
select * from student join father on student.stu_f=father.c_id where (student.stu_age=(select max(stu_age) from student where stu_f=1))
or (student.stu_age=(select max(stu_age) from student where stu_f=2)) ;