有3个表1、学生表 结构
   学号
   姓名
   ……
2、成绩表
   学号
   科目
   成绩
3、补考成绩表
   学号
   科目
   成绩
   
要求查询的结果
学号  姓名  科目1的成绩  科目2的成绩  科目3的成绩  ……并且要求如果某人某科有补考成绩的就显示此科目补考的成绩

解决方案 »

  1.   

    select a.id,a.name,b.科目,decode(c.成绩,null,b.成绩,c.成绩)
    from 学生表 a,成绩表 b,补考成绩表 c
    where a.id=b.id
    and a.id=c.id
    and b.科目=c.科目(+)大致应该这样吧,可能有点错误,不过大致思路应该如此
      

  2.   

    这个只有将所有学科遍历一下,否则只能通过存储过程实现了,
    select t.no,t2.name ,nvl(sum("语文"),0) "语文",nvl(sum("数学"),0) "数学",nvl(sum("英语"),0) "英语"
    from (select no,
    case when Course='语文'  then nvl(SUM(score),0) end "语文",
    case when Course='数学'  then nvl(SUM(score),0) end "数学",
    case when Course='英语'  then nvl(SUM(score),0) end "英语"from 成绩表
    group by no,course) t,学生表 t2 
    where t.no=t2.no
    group by t.no,t2.name另外楼主太小气,也不给点分!