tables;
1.Student
studentID, name, DOB, address2.Major
MajorID, name,credit3.StudentMajor
SMID,studentID, MajorID, pass4.Teacher
TeacherID,Name, DOB,Address, Salary5.TeacherMajor
TMID,TeacherID, MajorIDQuestion 1:
Please write a SQL statement which can retrieve the total credit of the students they grant.
Sample output:
StudentID Name TotalCredit
----------- -------------------------------------------------- -----------
1 Alan Tsui 8
2 Ronstar 9
3 Steven 9
Question 2:
Please write a SQL statement to show which major has the highest PASS rate and which teacher teaches the major. (Hints: get the top 1 major with count (passed student) and then join the teacher table)
Sample output:
TeacherID TeacherName MajorID TotalPass Name
----------- ----------------------- ------------- -------------- -----------------------
1 Professor Ronstar 2 3 Business Management
1.Student
studentID, name, DOB, address2.Major
MajorID, name,credit3.StudentMajor
SMID,studentID, MajorID, pass4.Teacher
TeacherID,Name, DOB,Address, Salary5.TeacherMajor
TMID,TeacherID, MajorIDQuestion 1:
Please write a SQL statement which can retrieve the total credit of the students they grant.
Sample output:
StudentID Name TotalCredit
----------- -------------------------------------------------- -----------
1 Alan Tsui 8
2 Ronstar 9
3 Steven 9
Question 2:
Please write a SQL statement to show which major has the highest PASS rate and which teacher teaches the major. (Hints: get the top 1 major with count (passed student) and then join the teacher table)
Sample output:
TeacherID TeacherName MajorID TotalPass Name
----------- ----------------------- ------------- -------------- -----------------------
1 Professor Ronstar 2 3 Business Management
解决方案 »
- mysql innodb插入速度
- navicat for mysql使用【连接】-》【常规】,设置了root和密码,远程连接iP地址。
- 如何实现下面的循环计算?
- oracle函数改mysql,需要注意哪一些?
- 接上帖,多表查询问题
- 急急!新手任务很重啊!下面是个批处理文件里的内容,怎么理解啊?利用批处理怎么以每天日期为名字自动备份数据库??
- 求个SQL语句
- “my.ini”文件在哪里啊,我怎么找了半天也没有找到啊~~~哪位大哥说一下,我就这点分了。
- SOS!用什么方式才能让VB.NET和MySql访问??就要走上绝路啦:(
- 查询表格合并问题
- mysql 在DOS下无法输入中文!请教
- 创建约束后,插入数据失败?
1.
select a.Student,a.name,sum(b.MajorID) as 'TotalCredit' from Student a ,Major b ,StudentMajor c where a.studentID= c.studentID and b.MajorID= c.MajorID group by a.igroupid,a.cgroupname HAVING a.igroupid > 2
1. 正解:
select a.Student,a.name,sum(b.MajorID) as 'TotalCredit' from Student a ,Major b ,StudentMajor c where a.studentID= c.studentID and b.MajorID= c.MajorID group by a.Student,a.name
select a.TeacherID,a.name as 'TeacherName',b.MajorID,
count(c.studentID) as 'TotalPass',b.name as 'Name'
from Teacher a,Major b,StudentMajor c,TeacherMajor d
where a.TeacherID = d.TeacherID and d.MajorID = b.MajorID
and d.pass >= b.credit
group by a.TeacherID,a.name,b.MajorID,b.name
首先pass是studentMajor表中的字段。不过我理解这个pass应该是一个bool值(BIT),表示某个学生的某门课是否通过,感觉应该用集合函数MAX和COUNT,不过条件的确比较复杂……