本帖最后由 xjs_2009 于 2010-01-27 10:56:17 编辑

解决方案 »

  1.   

    是要输出结果?
    这个也不难的
    用ROW_NUMBER 这个分析函数就行了
      

  2.   

    用两层SQL
    第一层分组求合,把相同的product_id    charge_id  的合并数据
    第二层用row_number() over(partition by product_id  order by charge_id ) 来生成 SEQ
      

  3.   

    select a.*,row_number() over(partition by product_id  order by charge_id) seq
    from 
    (
    select product_id,charge_id
           sum(a_amount) a_amount,
           sum(b_amount) b_amount,
           sum(a_disc_amount)a_disc_amount,
           sum(b_disc_amount)b_disc_amount
    from table 
    group by product_id,charge_id
    ) a
      

  4.   

    过程写?用游标传出,还是修改表,生成视图什么的?
    一定要过程的话,基本上将该sql带入,稍作处理就行了
      

  5.   

    修改表。  在表中增加一个字段(SEQ)  SEQ根据product_id是否重复来自增 就像 "最终结果" 那样
      

  6.   


    create or replace procedure p1
    is
    begin
     create table s_table_bak as select * from s_table;--table 是你的源表
     
     delete from s_table; alter table s_table add column seq number;insert into s_table 
    select a.*,row_number() over(partition by product_id  order by charge_id) seq
    from 
    (
    select product_id,charge_id
           sum(a_amount) a_amount,
           sum(b_amount) b_amount,
           sum(a_disc_amount)a_disc_amount,
           sum(b_disc_amount)b_disc_amount
    from s_table_bak
    group by product_id,charge_id
    ) a
    end p1;