你可以建一个统计function,然后用以下方式调用:
select id,name,fun_sum(id) from table_name;
即可.

解决方案 »

  1.   

    这是在什么方式下得到的查询结果?如果是在sqlplus下面,需要
    break on id dup
    break on name dup
      

  2.   

    这是在程序里写SQL语句得到的结果
      

  3.   

    select id_null id,name_null name,sum_null sum,subno,subnum
    from
    (select id,'' id_null,'' name_null,0+null sum_null,subno,subnum
    from tab t1
    where exists(select 1 from tab where id=t1.id and subno<t1.subno)
    union all
    select id,id id_null,max(name) name_null,sum(subnum) sum_null,min(subno) subno,
    (select subnum from tab where id=t2.id and subno=t2.subno)subnum
    from tab t2
    group by id)t3
    order by id,subno;