select a.strno,a.strnam,b.sum(score) from 
(select strno,strnam from name where strnam >2) a,
(select strno,sum(score) from score where strdate>'1-1月-2009' group by strno having sum(score)>300) b
where a.strno=b.strno group by a.strno,a.strnam表A中是学号和学名,表B中是学号和成绩,我想输出一张今年学名大于2个字的,成绩大于300分的表格。
但是执行后总是报错,b.sum(score) 是无效标识符,请各位指点一下吧

解决方案 »

  1.   

    select a.strno,a.strnam,sum(b.score) from 
    (select strno,strnam from name where strnam >2) a, 
    (select strno,sum(score) from score where strdate>'1-1月-2009' group by strno having sum(score)>300) b 
    where a.strno=b.strno group by a.strno,a.strnam 
      

  2.   

    sum(b.score)应该也可以,总之sum是函数,应该放在外面,也可以加as起个别名,比如:sum(b.score) as bscore
      

  3.   

    select a.strno
         , a.strnam
         , sum(b.score) 
      from (select strno
                 , strnam 
              from name 
             where strnam >2
            ) a
         , (select strno
                 , sum(score) as score 
              from score 
             where strdate>'1-1月-2009' 
            group by strno 
            having sum(score)>300
            ) b 
    where a.strno=b.strno 
    group by a.strno,a.strnam 
      

  4.   

    select a.strno
         , a.strnam
         , sum(b.score) 
      from (select strno
                 , strnam 
              from name 
             where strnam >2
            ) a
         , (select strno
                 , sum(score) as score 
              from score 
             where strdate>'1-1月-2009' 
            group by strno 
            having sum(score)>300
            ) b 
    where a.strno=b.strno 
    group by a.strno,a.strnam 
      

  5.   

    谢谢大家参与,你们都建议改成sum(b.score),可是,还是提示
    ORA-00904:"B"."SCORE":无效的标识符
      

  6.   

    因为你这里score既是表名,又是字段名,所以建议使用#1楼的写法
      

  7.   

    select a.strno 
        , a.strnam 
        , sum(b.score) 
      from (select strno 
                , strnam 
              from name 
            where strnam >2 
            ) a 
        , (select strno 
                , sum(score) as score 
              from score 
            where strdate>'3-5月-2009' 
            group by strno 
            having sum(score)>100 
            ) b 
    where a.strno=b.strno 
    group by a.strno,a.strnam 
      

  8.   

    关键字 SUM(xx)   
      

  9.   

    select a.strno 
        , a.strnam 
        , b.score)
      from (select strno 
                , strnam 
              from name 
            where strnam >2 
            ) a 
        , (select strno 
                , sum(score) as score 
              from score 
              where strdate>'1-1月-2009'
            group by strno 
            having sum(score)>100 
            ) b 
    where a.strno=b.strno