先有四张表:
Student(Sno,Sname,Sage,Ssex) 学生表
Course(Cno,Cname,Tno) 课程表
SC(Sno,Cno,score) 成绩表
Teacher(Tno,Tname) 教师表 1)查询和“1002”号的同学学习的课程完全相同的其他同学学号和姓名;2)按各科平均成绩从低到高和及格率的百分数从高到低顺序
其表示格式:课程ID 课程名字 平均成绩 及格率麻烦高手给我讲讲怎么用SQL语句求及格率,最好是这种形式的 n%的,谢谢。
Student(Sno,Sname,Sage,Ssex) 学生表
Course(Cno,Cname,Tno) 课程表
SC(Sno,Cno,score) 成绩表
Teacher(Tno,Tname) 教师表 1)查询和“1002”号的同学学习的课程完全相同的其他同学学号和姓名;2)按各科平均成绩从低到高和及格率的百分数从高到低顺序
其表示格式:课程ID 课程名字 平均成绩 及格率麻烦高手给我讲讲怎么用SQL语句求及格率,最好是这种形式的 n%的,谢谢。
select A.Sno,A.Sname
from 学生表 A ,成绩表 B
where A.sno=B.sno and exists
(select 1 from from 成绩表 where C.sno=1002 and B.Cno=C.Cno)
select A.Sno,A.Sname
from 学生表 A ,成绩表 B
where A.sno=B.sno and exists
(select 1 from 成绩表 where C.sno=1002 and B.Cno=C.Cno)
select A.Cno,B.Cname,avg(B.score),sum(case when B.score>=60 then 1 else 0 end)/count(*)
from 成绩表 A,课程表 B
where A.Cno=B.Cno
group by A.Cno,B.Cname
order by 3 ,4 desc
where cname=(select cname form cname
on sc.cno=course.cno
wheresno='1002');
多看书,简单的也问,先帮你写一题,下面的自己写简单啊
表名不是后面的汉字。
From Studeng s,
Course c,
SC sc
where s.Sno = sc.Sno
and Sc.Cno = c.Cno
and sc.Sno = '1002'
不是题意“和“1002”号的同学学习的课程完全相同的其他同学学号和姓名”
select stu.Sno,Stu.Sname from student Stu,sc c
where c.Sno=Stu.Sno and c.Sno!='1002' and c.Cno
in (Select Cno from student where Sno='1002');
课结果仍不是我想要的,你这个SQL语句求出的是:至少有一门选的课程是学号'1002'选的同学的学号和姓名。
select student.* from student right join sc on student.sno = sc.sno and (sc.cno in(
select sc.cno from student left join sc on student.sno=sc.sno and student.sno='1002') and sc.sno<>'1002')
where b.cno in (select cno from sc where sno='1002')
group by a.sno,a.sname
having count(b.cno)=(select count(*) from sc where sno='1002')
查找和1002同学完全选课完全相同的学生
比如学号'1002'叫张三,他选的课是课A和课B,李四选的课也是课A和课B,
王五选的课是课A,课B和课C,按照题意的要求应该是,李四选的课和张三一模一样
可这段SQL语句出的结果还有王五。
from student a,course b
where a.sno=c.sno and b.cno = (select d.cno from student e,SC d where e.sno=d.sno)
from 学生表 A ,成绩表 B
where A.sno=B.sno and exists
(select 1 from 成绩表 C where C.sno=1002 and B.Cno=C.Cno)
王五选的课是课A,课B和课C,按照题意的要求应该是,李四选的课才是和张三一模一样
可这段SQL语句出的结果还有王五。
from 学生表 Stu,成绩表Sc
where Sc.Sno=Stu.Sno and Sc.Sno!=1002 and Sc.Cno in
(Select Cno
from 成绩表
where Sno=1002)
select SNO from SC where CNO in (select CNO from SC where SNO='1002')
group by SNO having count(*)=(select count(*) from SC where SNO='1002')
2)select cNO as 课程,avg(score) as 平均成绩,convert(varchar,100 * sum(case when isnull(score,0)>=60 then 1 else 0 end)/count(*))+'%' as 及格百分数
from sc group by cNO order by cNO,avg(score) asc ,100 * sum(case when isnull(score,0)>=60 then 1 else 0 end)/count(*) desc
也许还有另外的解决办法,期望看到
也许还有另外的解决办法,期望看到
也许还有另外的解决办法,期望看到