参考一下下边的
select id,bpid1,bpid2 from(
select id,minbpid,maxbpid,
(select money from a where id=a1.id and bpid=a1.minbpid)bpid1,
(select money from a where id=a1.id and bpid=a1.maxbpid)bpid2
from (select id,,min(bpid) minbpid,max(bpid) maxbpid from a group by id) a1);

解决方案 »

  1.   

    create table B as select ID ID, BPID BPID1, MONEY BPID2 from A;
      

  2.   

    不过表B只有数据,如果表A有主键,外键,索引什么的,表B都没有。
      

  3.   

    可以,用decode函数
    select id,sum(bpid1) bpid1,sum(bpid2) bpid2
    from (
          select id,sum(decode(bpid,1,money,0)) bpid1,sum(decode(bpid,2,money,0)) bpid2
          from 表A
          group by id
         )
    group by id
    ;
      

  4.   

    --创建数据源
    create table henry_test(id number(10),bpid number(10),money number(10));
    insert into henry_test values (1,1,100);
    insert into henry_test values (1,2,200);
    --楼主所要的SQL语句
    select id,sum(decode(bpid,1,money,0)),sum(decode(bpid,2,money,0)) from henry_test group by id;
    结果如下:
             ID SUM(DECODE(BPID,1,MONEY,0)) SUM(DECODE(BPID,2,MONEY,0))
    ----------- --------------------------- ---------------------------
              1                         100                         200
      

  5.   

    SQL> select id,sum(decode(bpid,1,money,0)) bpid1,sum(decode(bpid,2,money,0)) bpid2 from henry_test group by id;         ID      BPID1      BPID2
    ----------- ---------- ----------
              1        100        200
      

  6.   

    建议楼主有空研究下decode我也是初学。
      

  7.   

    select * from (select id,bpid bpid1 from a wehre id=1 and bpid = 1),(select bpid bpid2 from a wehre id=1 and bpid = 2)