先有四张表:
Student(Sno,Sname,Sage,Ssex) 学生表 
Course(Cno,Cname,Tno) 课程表 
SC(Sno,Cno,score) 成绩表 
Teacher(Tno,Tname) 教师表 1)查询和“1002”号的同学学习的课程完全相同的其他同学学号和姓名;2)按各科平均成绩从低到高和及格率的百分数从高到低顺序
   其表示格式:课程ID  课程名字  平均成绩  及格率麻烦高手给我讲讲怎么用SQL语句求及格率,最好是这种形式的 n%的,谢谢。

解决方案 »

  1.   

    1.
    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)
      

  2.   

    老大,你的Student表和Course都没有关联啊,怎么查询
      

  3.   

    上面多一个from 
    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) 
      

  4.   

    2.
    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
      

  5.   

    select Sno,Sname from Student 
     where cname=(select cname form cname 
     on sc.cno=course.cno
    wheresno='1002');
    多看书,简单的也问,先帮你写一题,下面的自己写简单啊
      

  6.   

    1、select stu.Sno,Stu.Sname from 学生表 Stu,成绩表Sc where Sc.Sno=Stu.Sno and Sc.Sno!=1002 and Sc.Cno in (Select Cno from 成绩表 where Sno=1002)
      

  7.   

    是简单,可你也没写对啊,看你的SQL语句,压根就没cname表,你哪来的cname表,where sno你也不用写在一起啊,自己看明白了再训人。
      

  8.   

    这四个表的名字是Student、Course、SC、Teacher
    表名不是后面的汉字。
      

  9.   

    1,Select  s.Sno 学号,s.姓名
        From   Studeng s, 
              Course c,
              SC sc
       where  s.Sno = sc.Sno
          and Sc.Cno = c.Cno
          and sc.Sno = '1002'
      

  10.   

    你这也不对,表名是字母,可能是我的疏忽,课你的C.sno里的C是什么啊?
      

  11.   

    你这不对,书写细节就不说了,你这个SQL语句本意是求学号为'1002'的学号和姓名,
    不是题意“和“1002”号的同学学习的课程完全相同的其他同学学号和姓名”
      

  12.   

    你这个我修改了下
    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'选的同学的学号和姓名。
      

  13.   

    1.
    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')
      

  14.   

    select a.sno,a.sname from Student a join Sc b on a.sno=b.sno 
    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同学完全选课完全相同的学生
      

  15.   

    我靠,你编的啥SQL啊,是木马吧,为啥我一运行你的语句,就弹出个“未捕获的异常”要我用调试,还把我的MySQL停止了。
      

  16.   

    开始我也这么想的,不过结果并不对
    比如学号'1002'叫张三,他选的课是课A和课B,李四选的课也是课A和课B,
    王五选的课是课A,课B和课C,按照题意的要求应该是,李四选的课和张三一模一样
    可这段SQL语句出的结果还有王五。
      

  17.   

    select a.sno,a.sname,a.sage.a.ssex
    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)
      

  18.   

    select A.Sno,A.Sname 
    from 学生表 A ,成绩表 B 
    where A.sno=B.sno and exists 
    (select 1 from 成绩表 C where C.sno=1002 and B.Cno=C.Cno) 
      

  19.   

    如果张三是'1002',他选的课是课A和课B,李四选的课也是课A和课B, 
    王五选的课是课A,课B和课C,按照题意的要求应该是,李四选的课才是和张三一模一样 
    可这段SQL语句出的结果还有王五。
      

  20.   

    select stu.Sno,Stu.Sname 
    from 学生表 Stu,成绩表Sc 
    where Sc.Sno=Stu.Sno and Sc.Sno!=1002 and Sc.Cno in 
         (Select Cno 
          from 成绩表 
           where Sno=1002) 
      

  21.   

    select Sno,Sname form Student where Sno in(select Sno from SC A,SC B where A.Cno = B.Cno and A.Sno != '1002' and B.Sno != '1002')
      

  22.   

    1)
     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
      

  23.   

    这道题会不会道上了SQL语句的缺陷,都好像没一个适合关键字来用,18楼和31楼写的本来应该也适合的,用所求的学生学的科数=“1002”同学学的科数,可是就是没办法写出  所求的学生学的科数 
    也许还有另外的解决办法,期望看到
      

  24.   

    这道题会不会道上了SQL语句的缺陷,都好像没一个适合关键字来用,18楼和31楼写的本来应该也适合的,用所求的学生学的科数=“1002”同学学的科数,可是就是没办法写出  所求的学生学的科数 
    也许还有另外的解决办法,期望看到
      

  25.   

    第一题会不会道上了SQL语句的缺陷,都好像没一个适合关键字来用,18楼和31楼写的本来应该也适合的,用所求的学生学的科数=“1002”同学学的科数,可是就是没办法写出  所求的学生学的科数 
    也许还有另外的解决办法,期望看到