SELECT A.ID,A.MONTH,B.POINTS 
FROM
   (SELECT ID,COL1 AS MONTH
   FROM YOURTABLENAME
   WHERE COL1='MONTH'
   ) A
   ,(SELECT ID,COL1 AS POINTS
   FROM YOURTABLENAME
   WHERE COL1='POINTS'
   ) B
WHERE
   A.ID=B.ID

解决方案 »

  1.   

    create table t (id varchar2(2),a varchar2(8),b number(4));
    insert into t values('1','month',10);
    insert into t values('1','points',1000);
    insert into t values('2','month',12);
    insert into t values('2','points',5000);select id,sum(decode(a,'month',b,0))month,
              sum(decode(a,'points',b,0))points
              from t
              group by id;
      

  2.   

    豆腐干写的可以,但是有些笔误.应该是
    SELECT ID,COL2 AS MONTH
       FROM YOURTABLENAME
       WHERE COL1='MONTH'
    而不是
    SELECT ID,COL1 AS MONTH
       FROM YOURTABLENAME
       WHERE COL1='MONTH'而且在关联时如果不能保证每一个号码都有Month 和Points最好写成外关联.
    总和而言就是
    SELECT A.ID,A.MONTH,B.POINTS 
    FROM
       (SELECT ID,COL2 AS MONTH
       FROM YOURTABLENAME
       WHERE COL1='MONTH'
       ) A
       ,(SELECT ID,COL2 AS POINTS
       FROM YOURTABLENAME
       WHERE COL1='POINTS'
       ) B
    WHERE
       A.ID(+)=B.ID(+)
      

  3.   

    select id,sum(decode(month,'month',p)),sum(decode(month,'points',p)) from t_1 group by id;
      

  4.   

    SQL> select * from t_1;        ID MONTH                         P
    ---------- -------------------- ----------
             1 month                        10
             1 points                     1000
             2 month                        12
             2 points                     5000SQL> select id,sum(decode(month,'month',p)) month,sum(decode(month,'points',p)) points from t_1 group by id
      2  ;        ID      MONTH     POINTS
    ---------- ---------- ----------
             1         10       1000
             2         12       5000SQL>