两个表: 1.学生(学号 c(6),姓名c(6),性别c(2),专业c(6),入学总分N(5,1)出生日期date)
          2. 选课(学号C(6),课程号C(4)成绩N(4,1))
1.查询X同学所有得分
2.通过两表查出数据库成绩大于一班平均成绩的人
3.查出数据库成绩=85的学生姓名
4.查数据库课的平均成绩

解决方案 »

  1.   

    1.select XK.* from 选课 XK left join 学生 XS on XK.学号=XS.学号 where XS.姓名='X' order by XS.学号
    2.select XS.* from 学生 XS where 学号 in (select 学号 from 选课 where 成绩 >(select avg(成绩) from 选课 where 课程号='数据库的课程号') and 课程号='数据库的课程号')
    3.select 姓名 from 学生 XS where XS.学号 in (select 学号 from 选课 where 课程号='数据库的课程号' and 成绩=85)
    4.select avg(成绩) from 选课 where 课程号='数据库的课程号'
      

  2.   

    select xs.姓名,xk.课程号,xk.成绩
      from 选课 xk,学生 xs
     where xk.学号=xs.学号
       and xs.姓名='X'select xs.姓名,xk.课程号,xk.成绩
      from 选课 xk,学生 xs
     where xk.学号=xs.学号
       and xk.课程号='数据库'
       and xk.成绩 > (select avg(xk1.成绩)
                        from 选课 xk1,学生 xs1 
                       where xk1.学号=xs1.学号
                         and xk.课程号=xk.课程号)  select xs.姓名,xk.课程号,xk.成绩
      from 选课 xk,学生 xs
     where xk.学号=xs.学号
       and xk.课程号='数据库'
       and xk.成绩=85
    select xk.课程号,avg(xk.成绩) as 平均成绩
      from 选课 xk,学生 xs
     where xk.学号=xs.学号
       and xk.课程号='数据库'
       group by xk.课程号