Cracking the coding interview--Q15.5
2014-03-25 09:57
232 查看
题目
原文:
Imagine a simple database storing information for students’ grades. Design what this database might look like, and provide a SQL query to return a list of the honor roll
students (top 10%), sorted by their grade point average.
译文:
假设有一个简单的数据库,存储学生的成绩,设计这样的一个数据库:提供sql的查询光荣榜列表的前%10的学生的信息,并按照他们的GPA 排序。
解答
在一个简单的数据库中,我们至少需要以下三张表:学生表(Students),课程表(Courses), 及课程登记表(CourseEnrollment)。学生表中至少需要有学生姓名和学生ID, 及其它的个人信息。课程表包含课程名和课程ID,还可以包含课程描述和授课老师等。 课程登记表将包含学生和课程对(即哪个学生选了什么课,某课程有哪些学生选), 还包含课程成绩等。我们假设课程成绩是一个整数。
获取光荣榜学生的SQL语句如下:
转自:http://hawstein.com/posts/15.5.html
更多数据库练习:http://blog.csdn.net/zbdba/article/details/16806937
---EOF---
原文:
Imagine a simple database storing information for students’ grades. Design what this database might look like, and provide a SQL query to return a list of the honor roll
students (top 10%), sorted by their grade point average.
译文:
假设有一个简单的数据库,存储学生的成绩,设计这样的一个数据库:提供sql的查询光荣榜列表的前%10的学生的信息,并按照他们的GPA 排序。
解答
在一个简单的数据库中,我们至少需要以下三张表:学生表(Students),课程表(Courses), 及课程登记表(CourseEnrollment)。学生表中至少需要有学生姓名和学生ID, 及其它的个人信息。课程表包含课程名和课程ID,还可以包含课程描述和授课老师等。 课程登记表将包含学生和课程对(即哪个学生选了什么课,某课程有哪些学生选), 还包含课程成绩等。我们假设课程成绩是一个整数。
获取光荣榜学生的SQL语句如下:
SELECT StudentName, GPA FROM ( SELECT top 10 percent Avg(CourseEnrollment.Grade) AS GPA, CourseEnrollment.StudentID FROM CourseEnrollment GROUP BY CourseEnrollment.StudentID ORDER BY Avg(CourseEnrollment.Grade)) Honors INNER JOIN Students ON Honors.StudentID = Students.StudentID
转自:http://hawstein.com/posts/15.5.html
更多数据库练习:http://blog.csdn.net/zbdba/article/details/16806937
---EOF---
相关文章推荐
- Cracking the coding interview–Q1.3
- Cracking the coding interview--Q1.4
- Cracking The Coding Interview--Q1.1
- Cracking the coding interview--Q2.5
- Cracking the coding interview--Q3.4
- Cracking the coding interview--Q3.6
- Cracking the coding interview--问题与解答
- Cracking the Coding Interview 10.7
- Cracking the coding interview--Q8.3
- { Cracking The Coding Interview: 150 programming Q&A } --- Arrays and Strings
- Cracking the coding interview--Q1.1
- Cracking the coding interview--Q1.6
- Cracking the coding interview--Q17
- Cracking the coding interview--Q12.4
- 《Cracking the Coding Interview》——第2章:链表——题目7
- Cracking the coding interview--问题与解答
- 《Cracking the Coding Interview》——第4章:树和图——题目2
- 《Cracking the Coding Interview》——第5章:位操作——题目8
- Cracking the coding interview--Q2.4
- 《Cracking the Coding Interview》——第6章:智力题——题目3