select stu_no,stu_name,score from tbname where stu_no<100003
union all
select '','合计',sum(score),from tbname where stu_no<100003;

解决方案 »

  1.   

    select stu_no,stu_name,score from table_name where stu_no<100003
    union all
    select null,'合计',sum(score) from table_name where stu_no<100003
      

  2.   

    有个小问题,如果 from 和where的内容比较多
    这样会不会效率比较低?
    select stu_no,stu_name,score from tbname where stu_no<100003
    union all
    select '','合计',sum(score),from tbname where stu_no<100003;
    实际上第一个select已经把第二次要用的结果选出来了呀,如果不用临时表,怎样利用这个结果?
    我是举的一个简化的例子,实际上要关联的表较多,数据量较大,有没有好一点的办法?
      

  3.   

    以前有人问过了。
    http://www.csdn.net/news/newstopic/18/18265.shtml
    有oracle杂志下载,上面有你要看的文章。关于怎么把合计附在查询结果后面。