select 
case t1.d1 + t2.v1 + t2.c1 
begin
then t1.d1 
else ''
end from t1 inner join t2 
on t1.id= t2.id大概这样吧没测试过。。    如果不需要空的数据 这个就算子查询外面+一层就可以乐吧

解决方案 »

  1.   

    select
        a.*
    from
        T1 a,T2 b
    where
        a.ID = b.ID 
        and 
        b.l = 'and' 
        and 
        1 = (case when b.v1='>' and a.d1>b.c1 then 1
                  when b.v1='=' and a.d1=b.c1 then 1
                  when b.v1='<' and a.d1<b.c1 then 1
             end)
        and
        1 = (case when b.v2='>' and a.d2>b.c2 then 1
                  when b.v2='=' and a.d2=b.c2 then 1
                  when b.v2='<' and a.d2<b.c2 then 1
             end)
    union all
    select
        a.*
    from
        T1 a,T2 b
    where
        a.ID = b.ID 
        and 
        b.l = 'and' 
        and 
        (1 = (case when b.v1='>' and a.d1>b.c1 then 1
                   when b.v1='=' and a.d1=b.c1 then 1
                   when b.v1='<' and a.d1<b.c1 then 1
              end)
         or
         1 = (case when b.v2='>' and a.d2>b.c2 then 1
                   when b.v2='=' and a.d2=b.c2 then 1
                   when b.v2='<' and a.d2<b.c2 then 1
              end))
      

  2.   

    libin_ftsafe(子陌红尘) 好厉害的说哈
      

  3.   

    我也是新手。。刚接触sql 这里也向高人学习一下
      

  4.   

    libin_ftsafe(子陌红尘)正确,不过下面的'and'要改成'or'
    select
        a.*
    from
        T1 a,T2 b
    where
        a.ID = b.ID 
        and 
        b.l = 'and' 
        and 
        1 = (case when b.v1='>' and a.d1>b.c1 then 1
                  when b.v1='=' and a.d1=b.c1 then 1
                  when b.v1='<' and a.d1<b.c1 then 1
             end)
        and
        1 = (case when b.v2='>' and a.d2>b.c2 then 1
                  when b.v2='=' and a.d2=b.c2 then 1
                  when b.v2='<' and a.d2<b.c2 then 1
             end)
    union all
    select
        a.*
    from
        T1 a,T2 b
    where
        a.ID = b.ID 
        and 
        b.l = 'or'--这里改成'or' 
        and 
        (1 = (case when b.v1='>' and a.d1>b.c1 then 1
                   when b.v1='=' and a.d1=b.c1 then 1
                   when b.v1='<' and a.d1<b.c1 then 1
              end)
         or
         1 = (case when b.v2='>' and a.d2>b.c2 then 1
                   when b.v2='=' and a.d2=b.c2 then 1
                   when b.v2='<' and a.d2<b.c2 then 1
              end))