数据库系统概念第六版答案(包括实践习题,习题)例如3.11答案Exercises
•Write the following queries in SQL, using the university schema.
•Find the names of all students who have taken at least one Comp. Sci. course; make sure there are no duplicate names in the result.
•Find the IDs and names of all students who have not taken any course offering before Spring 2009.
11
•For each department, find the maximum salary of instructors in that department. You may assume that every department has at least one instructor.
•Find the lowest, across all departments, of the per-department max- imum salary computed by the preceding query.
Answer:
•SQL query:
select name
from student natural join takes natural join course
where course.dept = ’Comp. Sci.’
•SQL query:
select id, name from student except
select id, name
from student natural join takes
where year < 2009
Since the except operator eliminates duplicates, there is no need to use a select distinct clause, although doing so would not affect correctness of the query.
•SQL query:
select dept, max(salary) from instructor
group by dept
1