表a
    name     time               
      a        200910
      a        200909
      a        200908
      b        200908
      b        200910
表b
    name       time
      a        200810
      a        200809
      a        200808
      b        200808
      b        200810
查询出来的表为 
     name       time    name    time
      a        200810   a     200910
      a        200809   a     200909
      a        200808   a     200908
      b        200808   b     200908
      b        200810   b     200910     其实就是一张表传入的 name 是相同的  时间不同而已   怎么做查出上面的结果?

解决方案 »

  1.   

    没说清楚连接条件是什么,是两个字段name相同,相差一年,还是按顺序对接而已select *
    from a,b
    where a.name=b.name
      and a.time=to_char(add_months(to_date(b.time,'yyyymm'),-1),'yyyymm')
      

  2.   

    传入的条件就是 name  和   time,我上面说到 name是相同的  不同的只是时间
      

  3.   

    其实用 月份作为连接条件,但是查出来 多了 四条记录,连接里面有两个相同的月!
    也不是我想要的结果,我就是想把两张表拼起来
           name      time    name    time 
          a        200810  a    200910 
          a        200809  a    200909 
          a        200808  a    200908 
          b        200808  b    200908 
          b        200810  b    200910  
          b        200808  b    200908 
          a        200808  a    200908 
          a        200810  a    200910 
      

  4.   

    create table t_a(name varchar2(20),time  varchar2(20));
    create table t_B(name varchar2(20),time  varchar2(20));
    --生成A表数据
    insert into T_A (NAME, TIME)
    values ('a', '200910');
    insert into T_A (NAME, TIME)
    values ('a', '200909');
    insert into T_A (NAME, TIME)
    values ('a', '200908');
    insert into T_A (NAME, TIME)
    values ('b', '200908');
    insert into T_A (NAME, TIME)
    values ('b', '200910');--生成B表数据
    insert into T_B (NAME, TIME)
    values ('a', '200810');
    insert into T_B (NAME, TIME)
    values ('a', '200809');
    insert into T_B (NAME, TIME)
    values ('a', '200808');
    insert into T_B (NAME, TIME)
    values ('b', '200808');
    insert into T_B (NAME, TIME)
    values ('b', '200810');--得出结果
    Select c.Name,c.Time,c.Name,d.Time
    From (Select a.*,Rownum Row_Num from t_a a Order By a.Name) C,
    (Select b.*,Rownum Row_Num from t_b b Order By b.Name)D
    Where c.Name=d.Name
    And c.Row_Num=d.Row_Num;