[问题]关于几个SQL题目的问题
发表于 : 2007-10-31 1:59
This is a very good practice for you to assess your knowledge of writing SQL queries.
Problem Description
You were identified as the SQL expert in the company. Your manager has given you the
following relational schema
(下面粗体的是primary keys of the relation):
STUDENT (sid, sname, sex, age, year, averagegrade)
SCHOOL (dname, numhonours)
PROF (pname, dname)
COURSE (dname, cno, cname)
MAJOR (dname, sid)
CLASS (dname, cno, classno, pname)
ENROLL (sid, dname, cno, classno, grade)
Design SQL queries that answer the questions given below (one query per question). The answer
to each query should be duplicate free, but you should use DISTINCT only when necessary.
Questions
1. Show the names of courses offered by schools that have more than 50 honours students.
2. For every class offered by the business school, display the cno, classno, and the average age of
the students enrolled in the class.
3. Show the course names and the class numbers of all classes with fewer than 10 students
enrolled in.
4. List the course names and class numbers in which all its students are older than twenty-five
years old.
5. List the professors in which every class they teach has at least one student who is younger
than twenty.
6. Find the names and majors of the students who are taking at least two database related
courses, i.e, courses containing the word "database".
7. List the name of the schools and its number of honours students if the school has no major
containing “database” courses.
8. For each class from the SIT school, display the course number, class number, and the lowest
average grade of the students enrolled in that class. Sort the results in ascending order of
lowest average grade.
9. List the student names with the second highest average grade in their major schools.
10. List the student names who are taking courses from either the SIT school or the business
school, but not from both.
我刚开始接触SQL不久.第一个题目的话看起来好像是要显示有大于50个honours students 的course name.但是在COURSE表里没有numhonours,那该怎么写才是正确的呢?
我尝试写的是
SELECT numhonours
FROM SCHOOL
WHERE numhounours>50;
但感觉应该是错的...因为要求的是显示course name吧....=. =;;
求达人解答.下面几道题可以的话也请麻烦给出你的解答好让我学习下.谢谢
Problem Description
You were identified as the SQL expert in the company. Your manager has given you the
following relational schema
(下面粗体的是primary keys of the relation):
STUDENT (sid, sname, sex, age, year, averagegrade)
SCHOOL (dname, numhonours)
PROF (pname, dname)
COURSE (dname, cno, cname)
MAJOR (dname, sid)
CLASS (dname, cno, classno, pname)
ENROLL (sid, dname, cno, classno, grade)
Design SQL queries that answer the questions given below (one query per question). The answer
to each query should be duplicate free, but you should use DISTINCT only when necessary.
Questions
1. Show the names of courses offered by schools that have more than 50 honours students.
2. For every class offered by the business school, display the cno, classno, and the average age of
the students enrolled in the class.
3. Show the course names and the class numbers of all classes with fewer than 10 students
enrolled in.
4. List the course names and class numbers in which all its students are older than twenty-five
years old.
5. List the professors in which every class they teach has at least one student who is younger
than twenty.
6. Find the names and majors of the students who are taking at least two database related
courses, i.e, courses containing the word "database".
7. List the name of the schools and its number of honours students if the school has no major
containing “database” courses.
8. For each class from the SIT school, display the course number, class number, and the lowest
average grade of the students enrolled in that class. Sort the results in ascending order of
lowest average grade.
9. List the student names with the second highest average grade in their major schools.
10. List the student names who are taking courses from either the SIT school or the business
school, but not from both.
我刚开始接触SQL不久.第一个题目的话看起来好像是要显示有大于50个honours students 的course name.但是在COURSE表里没有numhonours,那该怎么写才是正确的呢?
我尝试写的是
SELECT numhonours
FROM SCHOOL
WHERE numhounours>50;
但感觉应该是错的...因为要求的是显示course name吧....=. =;;
求达人解答.下面几道题可以的话也请麻烦给出你的解答好让我学习下.谢谢