select a.*,null,null,null from a where name  in (select name from a minus select name from b)
union
select null,null,null,b.* from b where name  in (select name from b minus select name from a)

解决方案 »

  1.   

    select y.a, y.b-x.b from test_y x, test_y y where x.a(+)=y.a-1;a is the date column, and b is the sum value.
      

  2.   

    CREATE TABLE SCOTT.TEST1
    (
        A                              DATE,
        B                              NUMBER,
        C                              NUMBER
    )
    /SQL> select * from test1;A                    B          C
    ----------- ---------- ----------
    2002-5-6           550 
    2002-5-8           660 
    2002-5-11          690 
    2002-6-1           700 SQL> select a,b,b-(select max(b) from test1 t1 where t1.a<t.a) c from test1 t;A                    B          C
    ----------- ---------- ----------
    2002-5-6           550 
    2002-5-8           660        110
    2002-5-11          690         30
    2002-6-1           700         10
      

  3.   

    no 修改一下:
    CREATE TABLE SCOTT.TEST1
    (
        A                              DATE,
        B                              NUMBER)
    /SQL> select * from test1;A                    B          
    ----------- ---------- 
    2002-5-6           550 
    2002-5-8           660 
    2002-5-11          690 
    2002-6-1           700 SQL> select a,b,b-(select max(b) from test1 t1 where t1.a<t.a) c from test1 t;A                    B          C
    ----------- ---------- ----------
    2002-5-6           550 
    2002-5-8           660        110
    2002-5-11          690         30
    2002-6-1           700         10
      

  4.   

    select a1.*, (a2.累计量-a1.累计量)
     from a1,a2
    where a1.时间=a2.时间 -1
      

  5.   

    这些问题,自己好好想想首先试图通过一个SQL语句写出来,
    实在不行,可以通过存储过程,先写到临时表里,然后再从临时表里查询。
      

  6.   

    如果日期是连续的可以这样:
    select a.a 日期,a.b 累计量,a.b-(select b.b from test10 b where b.a=a.a-1) 日累计量 from test10 a  order by a
      

  7.   

    CREATE TABLE T1(RIQI DATE,NUM NUMBER);
    INSERT INTO T1 VALUES(SYSDATE-5,100);
    INSERT INTO T1 VALUES(SYSDATE-4,150);
    INSERT INTO T1 VALUES(SYSDATE-3,180);
    INSERT INTO T1 VALUES(SYSDATE-2,220);
    INSERT INTO T1 VALUES(SYSDATE-1,300);
    COMMIT;SELECT A.RIQI,A.NUM,A.NUM-B.NUM 
    FROM T1 A,T1 B
    WHERE TRUNC(A.RIQI)-1=TRUNC(B.RIQI(+));结果:
    RIQI              NUM A.NUM-B.NUM
    ---------- ---------- -----------
    17-11月-02        100
    18-11月-02        150          50
    19-11月-02        180          30
    20-11月-02        220          40
    21-11月-02        300          80