RT每次面试 都死在SQL语句上,问一下这个SQL语句如何写,请写下思路和答案,好了追加分,谢谢
题目:
给你三张表 S (SNO,SNAME)代表 (学号,姓名)
C (CNO,CNAME,CTEACHER)代表(课号,课名,教师) SC(SNO,CNO,SCGRADE)代表(学号,课号,成绩) 请用SQL语句查出以下结果。
1.找出没有选过“liming”老师的所有学生姓名。
2.找出2们(含2门)不及格学生姓名以及平均成绩。
3.即选过1号课程又选过2号课程所有学生的姓名请大侠写出答案,如果可以写上思路,在下不甚感激追加分,谢谢
题目:
给你三张表 S (SNO,SNAME)代表 (学号,姓名)
C (CNO,CNAME,CTEACHER)代表(课号,课名,教师) SC(SNO,CNO,SCGRADE)代表(学号,课号,成绩) 请用SQL语句查出以下结果。
1.找出没有选过“liming”老师的所有学生姓名。
2.找出2们(含2门)不及格学生姓名以及平均成绩。
3.即选过1号课程又选过2号课程所有学生的姓名请大侠写出答案,如果可以写上思路,在下不甚感激追加分,谢谢
解决方案 »
- 求高手:什么情况下会发生隐式commit和隐式rollback
- ORA-00959: 表空间 'MC_DATA' 不存在
- win7(64bit)在安装Oracle_11G时, PATH 环境变量的长度这个问题解决不了,还望各位高手帮忙解决下。谢谢了....
- 跪求oracleDBA大哥帮忙用oracle logminer解决查询某用户登录数据库记录的问题
- oracle spatial出现问题该如何解决
- pl/sql怎么执行索引语句
- oracle 10g 的安装配置问题
- 关于job
- 两台机器之间进行数据库的备份和恢复,无归档模式,请问如何进行整个数据库的恢复?
- PL/SQL Developer (5.1.2.682) 是否不兼容Oracle Client (9.2.0.1.0)?
- 关于ORACLE不支持某些罕见汉字的问题.求帮助...
- 一个链接到oracle数据库的固定连接频繁操作数据库遇到的问题!!!!!!!!!!!!!!!!!
1. select s.sname from S s, SC sc, C c where sc.cno = c.cno and sc.sno = s.sno and c.cteacher != 'liming';2. select s.sname,avg(sc.scgrade) from S s, SC sc, C c where s.no = sc.sno and
(select count(*) from SC cc where cc.scgrade < 60 and cc.sno = sc.sno) >= 2 group by s.sname;3. select s.sname from S s, SC sc, C c where s.no = sc.sno and (sc.cno in (1) and sc.cno in (2));
-- 1:选出没有选修过“liming”老师讲授课程的所有学生姓名
select sname from s where sno not in (select sno from sc,c where c.cno=sc.cno and cteacher='liming')--- 2:列出有两门以上(含两门)不及格课程的学生姓名及其平均成绩
select sname as 姓名, avg(scgrade)as 平均成绩 ,count(*) as 不及格课程数 from s inner join sc on s.sno=sc.sno
where scgrade<60
group by sname
having count(*)>=2--- 3:列出既学过“1”号课程,又学过“2”号课程的所有学生姓名
select sname as 姓名 from s where sno in (select sno from sc,c where c.cno=sc.cno and sc.cno=1 )and sno in
(select sno from sc,c where c.cno=sc.cno and sc.cno=2)
select sname from s where not exists (select 1 from c,sc where c.cno=sc.cno and cteacher='liming' and s.sno=sc.sno)
2.找出2们(含2门)不及格学生姓名以及平均成绩。
select sno,count(*) from s,sc where s.sno = sc.sno where scgrade<60 group by sno having count(*)>=2
select sno,avg(scgrade) from sc group by sno
3.即选过1号课程又选过2号课程所有学生的姓名
select sname from s where sno = (select sno from sc sc1,sc sc2 where sc1.sno=sc2.sno and sc1.cno='1' and sc2.cno='2')
select s.sname
from s,sc
where not exists (select 1 from c where c.cno=sc.cno and c.cteacher='liming')--找出2们(含2门)不及格学生姓名以及平均成绩
select s.sname from s
where sno in(select sno from sc
where grade<60
group by sno having(count(*)>=2)--两门不及格的学号--即选过1号课程又选过2号课程所有学生的姓名--选了1号课程的学生
select sname from s
where exists(select 1 from sc where s.sno=sc.sno and sc.cno=1)
intersect--求交集得到的就是既选了1号课程又选了2号课程的学生姓名
--选了2号课程的学生
select sname from s
where exists(select 1 from sc where s.sno=sc.sno and sc.cno=2)[/code]
写个最先老师教我们的子查询
1
select sname
from s
where sno not in(select distinct a.sno from sc,c where c.CTEACHER='liming' and sc.cno=c.cno)2
select s.sno,max(s.sname),avg(sc.成绩)
from s,sc
where s.sno=sc.sno
group by s.sno
having avg(sc.成绩)<60 and count(s.sno)=23
select s.*
from s,
(select sno
from sc
where cno in(1,2)
group by sno
having count(sno)=2) b
where s.sno=b.sno
exists是关键字吗?
不知道啊