首页 > 数据库技术 > 详细

mySQL 的 2个分类

时间:2017-04-10 22:19:56      阅读:188      评论:0      收藏:0      [点我收藏+]

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)) ;

mySQL 的 2个分类

原文:http://www.cnblogs.com/lq147760524/p/6691219.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!