oracle关联查询题目1数据库中有3 个表 teacher 表,student 表,tea_stu 关系表。teacher 表 teaID name agestudent 表 stuID name ageteacher_student 表 teaID stuID要求用一条sql 查询出这样的结果1.显示的字段要有老师name, age 每个老师所带的学生人数2 只列出老师age 为40 以下学生age 为12 以上的记录预备知识:1.sql 语句是对每一条记录依次处理,条件为真则执行动作(select,insert,delete,update)2.只要是迪卡尔积,就会产生“垃圾”信息,所以,只要迪卡尔积了,我们首先就要想到清除“垃圾”信息实验准备:drop table if exists tea_stu;drop table if exists teacher;drop table if exists student;create table teacher(teaID int primary key,name varchar(50),age int);create table student(stuID int primary key,name varchar(50),age int);create table tea_stu(teaID int references teacher(teaID),stuID int references student(stuID));insert into teacher values(1,'zxx',45), (2,'lhm',25) , (3,'wzg',26) , (4,'tg',27);insert into student values(1,'wy',11), (2,'dh',25) , (3,'ysq',26) , (4,'mxc',27);insert into tea_stu values(1,1), (1,2), (1,3);insert into tea_stu values(2,2), (2,3), (2,4);insert into tea_stu values(3,3), (3,4), (3,1);insert into tea_stu values(4,4), (4,1), (4,2) , (4,3);结果:2_3,3_2,4_3
oracle关联查询题目1
数据库中有3 个表 teacher 表,student 表,tea_stu 关系表。
teacher 表 teaID name age
student 表 stuID name age
teacher_student 表 teaID stuID
要求用一条sql 查询出这样的结果
1.显示的字段要有老师name, age 每个老师所带的学生人数
2 只列出老师age 为40 以下学生age 为12 以上的记录
预备知识:
1.sql 语句是对每一条记录依次处理,条件为真则执行动作(select,insert,delete,update)
2.只要是迪卡尔积,就会产生“垃圾”信息,所以,只要迪卡尔积了,我们首先就要想到清除“垃圾”信息
实验准备:
drop table if exists tea_stu;
drop table if exists teacher;
drop table if exists student;
create table teacher(teaID int primary key,name varchar(50),age int);
create table student(stuID int primary key,name varchar(50),age int);
create table tea_stu(teaID int references teacher(teaID),stuID int references student(stuID));
insert into teacher values(1,'zxx',45), (2,'lhm',25) , (3,'wzg',26) , (4,'tg',27);
insert into student values(1,'wy',11), (2,'dh',25) , (3,'ysq',26) , (4,'mxc',27);
insert into tea_stu values(1,1), (1,2), (1,3);
insert into tea_stu values(2,2), (2,3), (2,4);
insert into tea_stu values(3,3), (3,4), (3,1);
insert into tea_stu values(4,4), (4,1), (4,2) , (4,3);
结果:2_3,3_2,4_3