各位看官点个赞再走呗
任务描述
本关任务:创建大学数据库的教师信息表和开课信息表。
相关知识
大学数据库的整体设计
一个大学里面会有很多教学楼、学生、老师,他们之间的都有着密不可分的关系,因此将大学数据库整体设计如下图所示,总共涉及到八张表
答案:
#请在此添加创建开课信息表的SQL语句
########## Begin ##########
use universityDB;
create table instructor(
ID varchar(5) COMMENT'教师号',primary key(ID),
name varchar(20) COMMENT'教师名字'NOT NULL,
dept_name varchar(20) DEFAULT NULL COMMENT'教师所在的系',
salary numeric(8,2) COMMENT'薪资' check(salary>29000),
foreign key (dept_name) references department(dept_name)
on delete set null
);
create table section(
course_id varchar(8) COMMENT '课程号' ,
sec_id varchar(8) COMMENT'课程段标识',
semester varchar(6) COMMENT'学期' check(semester in('Fall','Winter','Spring','Summer')),
year numeric(4,0) COMMENT'年份',
building varchar(15) COMMENT '课程所在建筑' ,
room_number varchar(7) COMMENT '课程所在教室号' ,
time_slot_id varchar(4) COMMENT'时间档序号',
primary key (course_id, sec_id, semester, year),
foreign key (course_id) references course(course_id)
on delete cascade,
foreign key (building, room_number) references classroom(building, room_number)
on delete set null
);
########## End ##########
任务描述
本关任务:编写 sql 语句,输出符合条件的查询结果。
相关知识
为了完成本关任务,下面列出你可能需要使用到的表及数据。
答案:
#********* Begin *********#
echo "
select name
from student
where ID in
( select ID
from takes,course
where dept_name='Biology'
and takes.course_id=course.course_id
);
select name
from instructor
where salary >
(
select salary
from instructor
where dept_name='Biology'
);
select name, instructor.dept_name,building
from instructor,department
where instructor.dept_name= department.dept_name
;
select dept_name
from department
where building='Watson';
"
#********* End *********#
任务描述
本关任务:编写 sql 语句,输出符合条件的查询结果。
相关知识
为了完成本关任务,下面列出你可能需要使用到的表及数据。
答案:
#********* Begin *********#
echo "
SELECT count(distinct ID)
FROM teaches
WHERE semester = 'spring' AND year ='2010';
SELECT instructor.ID ,instructor.name,instructor.dept_name
FROM instructor
WHERE ID in(select ID from teaches where semester='Fall' and year='2009'
GROUP BY ID having count(ID)>=2);
SELECT dept_name,count(distinct instructor.ID) as instr_count
FROM instructor join teaches on instructor.ID = teaches.ID
WHERE semester = 'spring' and year = '2010'
GROUP BY dept_name;
"
#********* End *********#
任务描述
本关任务:编写 sql 语句,输出符合条件的查询结果。
相关知识
为了完成本关任务,下面列出你可能需要使用到的表及数据。
答案:
#********* Begin *********#
echo "
select instructor.*
from instructor order by salary desc, name asc;
select max(salary)
from instructor;
select dept_name
from instructor group by dept_name having avg(salary) >= all
(select avg(salary) from instructor group by dept_name);
select dept_name,avg(salary) as avg_salary
from instructor group by dept_name
having avg(salary)>50000 order by dept_name asc, avg_salary desc;
"
#********* End *********#
任务描述
本关任务:编写 sql 语句,输出符合条件的查询结果。
相关知识
为了完成本关任务,下面列出你可能需要使用到的表及数据。
答案:
#********* Begin *********#
echo "
select distinct course_id
from section
where semester='Fall' and year=2009 and
course_id not in (select course_id from section where semester='Spring' and
year=2010);
select course_id
from section as S
where year=2009 and semester='Fall' and exists
(select section.* from section as T where year=2010 and semester='Spring' and
S.course_id=T.course_id);
select course_id
from section
where year=2009 and semester='Fall' union all select
course_id from section where year=2010 and semester='Spring';
select course_id,semester,year,sec_id,avg(tot_cred)
from takes join student join department on takes.ID = student.ID
where year=2009 group by course_id,semester,year,sec_id having count(takes.ID)>=13;
"
#********* End *********#
任务描述
本关任务:编写 sql 语句,输出符合条件的查询结果。
相关知识
为了完成本关任务,下面列出你可能需要使用到的表及数据。
答案:
#********* Begin *********#
echo "
select instructor.name,teaches.course_id
from instructor,teaches
where instructor.ID=teaches.ID and dept_name='Physics';
select name
from instructor
where dept_name='Physics' and salary>80000;
update instructor set salary = case when salary <= 100000 then salary*1.05 else salary*1.03 end;
create view Physics_fall_2009 as select course.course_id,building,room_number from course,section where course.course_id = section.course_id and course.dept_name='Physics' and section.semester='Fall' and section.year='2009';
"
#********* End *********#