关于Oracle数据库编程题的解答。谢谢各位!

在数据库成绩管理中有三张表:学生表:Student(Sno,Sname,Sage,Ssex)课程表:Course(Cno,Cname,Tno)成绩表:SC(Sno,Cno... 在数据库成绩管理中有三张表:
学生表:Student(Sno,Sname,Sage,Ssex)
课程表:Course(Cno,Cname,Tno)
成绩表:SC(Sno,Cno,score)
教师表:Teacher(Tno,Tname)
用T-SQL命令完成以下题目。

1、查询姓“李”的老师的个数;

2、查询学过“c001”并且也学过编号“c002”课程的同学的学号、姓名;

3、查询学过“叶平”老师所教的所有课的同学的学号、姓名;

4、查询“c001”课程比“c002”课程成绩高的所有学生的学号

5、查询平均成绩大于60分的同学的学号和平均成绩;

6、查询所有同学的学号、姓名、选课数、总成绩;

7、查询没有学全所有课的同学的学号、姓名;
各位大虾,请指教指教啦!小弟在此感激不尽啊!!
展开
 我来答
flyingFish211
2010-12-21 · TA获得超过2.1万个赞
知道大有可为答主
回答量:1.5万
采纳率:50%
帮助的人:1.1亿
展开全部
1、查询姓“李”的老师的个数;
SELECT COUNT(Tno) FROM Teacher WHERE Tname LIKE '李%'

2、查询学过“c001”并且也学过编号“c002”课程的同学的学号、姓名;

SELECT Sno, Sname
FROM Student
WHERE sno IN(SELECT sno
FROM (SELECT Sno FROM SC WHERE Cno = 'c001') t1
(SELECT Sno FROM SC WHERE Cno = 'c002') t2
WHERE t1.sno = t2.sno)

3、查询学过“叶平”老师所教的所有课的同学的学号、姓名;
SELECT Sno, Sname
FROM student
WHERE Sno IN(SELECT SC
FROM SC
WHERE CNO IN (SELECT CNO FROM Course WHERE Cname = '叶平')
GROUP BY SC HAVING COUNT(CNO) = (SELECT COUNT(CNO) FROM Course WHERE Cname = '叶平'))

4、查询“c001”课程比“c002”课程成绩高的所有学生的学号

SELECT C1.SC
FROM (SELECT SC, Score FROM SC WHERE Cno = 'c001') c1
(SELECT SC, Score FROM SC WHERE Cno = 'c002') c2
WHERE c1.SC = c2.SC
AND c1.Score > c2.Score
如果只有C1,而没有C2成绩,用这个好一点
SELECT SC
FROM (SELECT SC, Score FROM SC WHERE Cno = 'c001') c1
left join (SELECT SC, Score FROM SC WHERE Cno = 'c002') c2
ON c1.SC = c2.SC AND c1.Score > c2.Score

5、查询平均成绩大于60分的同学的学号和平均成绩;
SELECT Sno, AVG(score)
FROM SC GROUP BY Sno Having AVG(score) > 60

6、查询所有同学的学号、姓名、选课数、总成绩;
SELECT stu.Sno, stu.Sname, COUNT(Cno), SUM(score)
FROM Student stu, SC
WHERE stu.Sno = Sc.sno
GROUP BY stu.sno, stu.Sname

7、查询没有学全所有课的同学的学号、姓名;
SELECT Sno, Sname
FROM SC
WHERE Sno NOT IN (SELECT Sno
FROM SC
GROUP BY SC
HAVING COUNT(CNO) < (SELECT COUNT(DISTINCT CNO) FROM SC))
光点科技
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件... 点击进入详情页
本回答由光点科技提供
shenjun134
2010-12-21 · TA获得超过372个赞
知道小有建树答主
回答量:136
采纳率:50%
帮助的人:157万
展开全部
1.select count(tno) from teacher where tname like '李%';

2.SELECT stu.SID, stu.name
FROM SC t, student stu
WHERE cid ='001'
AND EXITS (SELECT 1 FROM SC WHERE cid = '002' AND sid = t.sid)
and t.sid = stu.sid;

3.select sno,sname from (select sno fromstudent sc,(select cno from teacher,course where tname='叶平') a where a.cno=sc.cno) b,student stu where b.sno=stu.sno;

4.select sno,sname from sc a,student stu where cno='c001' and exits(select 1 from sc where cno='c002' and a.score>sc.score) and a.sno=stu.sno;
5.select sno,aver(score) from sc group by sno having aver(score)>60;

6.select sno,sname,a.ccount,b.sscore from student stu left join (select sno,count(*) as ccount from sc group by sno ) a on a.sno=sut.sno left join (select sno,sum(score) as sscore from sc group by sno) b on b.sno=stu.sno;

7.select sno,sname from student,(select sno from sc group by sno having count(cno)<(select count(*) from course)) a where a.sno=student.sno;
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式