注册 登录
编程论坛 SQL Server论坛

初学者请求解答个问题

熊猫想睡觉 发布于 2006-11-16 21:06, 620 次点击

有三个表,格式如下:
students(学生表): sno(学号) sname(名字) sex(性别) sage(年龄) sdept(系别)
Enrollement(课程表):sno(学号) cno(选课) grade(成绩)
Courses(选课表) :cno(选课) cname(课程名) credits(学分)
要求:查询计算机系选修了课程名为Database并且成绩大于90分的学生的学号。

我学SQL还不到一个星期,请问各位大虾,我写的两种方法正确么?
select sno
from students,enrollment,courses
where sdept ='computer' and sno in (select sno from enrollment where grade>90
and cno in (select cno from courses where cname=‘database’))
或者
select sno
from students,enrollment,course
where students.sno=enrollment.sno and courses.cno=enrollment.cno
and sdept='computer' and cname='database' and grade>90

9 回复
#2
熊猫想睡觉2006-11-16 21:07
我自学SQL还不到一个星期,请大家帮忙帮我看下哈,对我以后学习会有很大帮助的,谢谢了。
#3
bygg2006-11-16 21:51
正不正确,放到查分析器中执行一下不就出来结果了?
#4
熊猫想睡觉2006-11-16 22:00
但是我电脑现在还没装SQL,因为时间紧迫,马上就考试啦,还没时间去下载SQL哦,帮忙看看哈。谢谢。
#5
bygg2006-11-16 22:10
select sno
from students,enrollment,course
where students.sno=enrollment.sno and courses.cno=enrollment.cno
and sdept='computer' and cname='database' and grade>90

这个没错
#6
熊猫想睡觉2006-11-16 22:29
第一个运用的子查询正确么?
#7
熊猫想睡觉2006-11-16 22:31
另外我想问下这论坛有QQ群什么的么?
#8
bygg2006-11-18 16:36
#9
hanbingchong2006-11-18 21:11

第一个应该可以吧

#10
潇洒老乌龟2006-11-18 23:21

有无数的人问这个问题,而且还有很多相关问题.
其表名,字段名一模一样,难道现在的大学使用的计算机课程或SQL语言都是同一本书?

有三个表,格式如下:
students(学生表): sno(学号) sname(名字) sex(性别) sage(年龄) sdept(系别)
Enrollement(课程表):sno(学号) cno(选课) grade(成绩)
Courses(选课表) :cno(选课) cname(课程名) credits(学分)
要求:查询计算机系选修了课程名为Database并且成绩大于90分的学生的学号。

只查学号
select Enrollement.sno
from Enrollement , Coureses
where Enrollement.cno = Coureses.cno and Enrollement.grade > 90 and Courses.cname = 'database'

如果还要查学生姓名等其他信息.
select students.* from students where sno in
(
select Enrollement.sno
from Enrollement , Coureses
where Enrollement.cno = Coureses.cno and Enrollement.grade > 90 and Courses.cname = 'database'
)

1