假设两个表:
test1
 A     B     C
 1     a     >1000
 1     b     <10
 2     a     >20
 3     c     <1200
test2
 D     E
 1     1010
 2     15
 3     1000
求一查询语句,结果如下:
 A    B    C      E
 1    a    >1000  1010
 3    c    <1200  1000

解决方案 »

  1.   

    我试过用case when和oracle的decode函数都不行
      

  2.   

    刚试了下用select* from test1 x,test2 y where x.A=y.D and (y.e>substr(x.c,2,length(x.c)) AND instr(x.c,'>')>0) OR (y.e<substr(x.c,2,length(x.c)) AND instr(x.c,'<')>0)
    能满足了要求,谁还有好的方法没
      

  3.   

    with a as
    (
    select 1 a,'a' b,'>1000' c from dual
    union all
    select 1,'b','<10' from dual
    union all
    select 2,'a','>20' from dual
    union all
    select 3,'c','<1200' from dual
    ),
    b as
    (select 1 d,1010 e from dual
    union all
    select 2 d,15 e from dual
    union all
    select 3 ,1000 from dual
    )
    select a,b,c,e from(
    select a,b,c,e,
    case when substr(c,1,1)='>' and  e>substr(c,2) then e 
         when substr(c,1,1)='<' and  e<substr(c,2) then e end  w
    from a ,b 
    where a.a=b.d )
    where w is not null
      

  4.   

    如果test1,test2表有很多数据你这肯定不行了