数据库相关查询

来源:百度知道 编辑:UC知道 时间:2024/07/06 11:40:15
select sname from student where exists
(select * from sc where sno=student.sno and cno='1')

怎么理解?
sno=学号 cno=课程号

是想问exists?
就是exists后面的条件如果为真,则输出数据....不用想太复杂...呃...

个人理解:
找到课程号(cno)为1的姓名
select sname from student where //这句我想就不解释了
exists //用法是查找记录
(select * from sc where sno=student.sno and cno='1') //从sc表里查找条件为 学号=student的学号并且课程号为1的记录
exists (select * from sc where sno=student.sno and cno='1')
//连接起来的意思就是说查找是否有学号=student的学号并且课程号为1的记录
select sname from student where exists
(select * from sc where sno=student.sno and cno='1') //所以理解为从student表里查找学号为1的姓名
^ ^如有不对请各位高人指出,本人也是新手~希望对你有帮助!

就是要查询 SC 表里是否有 sno=student.sno 和 cno='1' 和人的数据

就是查出所有选修了课程'1'的学生名称。

查询所有选修了课程1的学生的姓名

查询所有选修了课程'1'的学生姓名...