select sum(je) from t_jetj
 where areaid like '1%' and  phonenum not like
  (select phonenum from t_phonenum where num like '1%' )+'%'求指教,上面伪SQL该怎么改

解决方案 »

  1.   

    try this,declare @tsql varchar(6000),@x varchar(200)select @x=phonenum from t_phonenum where num like '1%'select @tsql='select sum(je) from t_jetj
                  where areaid like ''1%'' 
                  and phonenum not like '''+@x+'%'' 'exec(@tsql)
      

  2.   


    SELECT SUM(je)
    FROM t_jetj AS A WITH(NOLOCK) INNER JOIN
    t_phonenum AS B WITH(NOLOCK) ON A.phonenum NOT LIKE B.phonenum+'%'
    AND A.areaid LIKE '1%'
    AND B.num LIKE '1%'改成这样试试。
      

  3.   

    select sum(je) from t_jetj,phonenum=(select phonenum from t_phonenum where num like '1%')
     where areaid like '1%' and  phonenum not like (phonenum+'%')
    你试试,我没有数据,所以不知道可以不?
      

  4.   

    貌似不行,这条语句的结果是全表sum的好几倍。。
      

  5.   

    这是SQL server的写法吧,我用的是oracle,还没改成oracle的
      

  6.   

    不需要用代码组合也可以的。select sum(je) 
    from t_jetj a 
    left join (select phonenum from t_phonenum where num like '1%' ) t on t.phonenum=left(a.phonenum,len(rtrim(t.phonenum))) 
    where areaid like '1%' and t.phonenum is null