怎样将查询出来的结果作为另一个查询的条件
例如:
将select distinct substr(filter,4) from t_Wage_Status
 where companyid = '43f00833-586d-4f53-81c7-1e10f528ca9c' 
 and year = 2012 and month = 10   (A)
查出来的结果作为select * from t_wage_personnel  (B)的条件问题:
  select * from t_wage_personnel 
 where 
      (
         select distinct substr(filter,4) from t_Wage_Status
          where companyid = '43f00833-586d-4f53-81c7-1e10f528ca9c' 
          and year = 2012 and month = 10 
      ) 
  为什么不行?求解补充:A查询出来的结果是
 CompanyID='43f00833-586d-4f53-81c7-1e10f528ca9c' AND EMPLOYEETYPE='1' 这样的

解决方案 »

  1.   

    你试试这样
    select * from t_wage_personnel 
     where 
          (
             select distinct substr(filter,4) from t_Wage_Status
              where companyid = '43f00833-586d-4f53-81c7-1e10f528ca9c' 
              and year = 2012 and month = 10 
          )  || ' and 1' = '1'
      

  2.   

    为什么要加上|| ' and 1' = '1' 这个呀
      

  3.   

    我试了下,运行的时候不报错了,但查不到数据,我直接将 
    select distinct substr(filter,4) from t_Wage_Status  where companyid = '43f00833-586d-4f53-81c7-1e10f528ca9c'  and year = 2012 and month = 10  查出来的结果
     CompanyID='43f00833-586d-4f53-81c7-1e10f528ca9c' AND EMPLOYEETYPE='1' AND TYPE<>'8'
    放到where的后面是可以查到数据的
      

  4.   

    我把=号改为!=号,就所有的数据都出来了,所以是不是||' and 1' = '1' 这里出了问题
    ||' and 1' = '1'可不可以理解为1等于"1",因为不等,所以没数据呀
      

  5.   


    额好像是的,你可以在 ||' and 1' = '1' 中把第一个1中加上单引号的转义字符,应该就可以了给分啊,lZ。。
      

  6.   

    貌似不是这个问题诶
    我把它改成这样
      select * from t_wage_personnel where '1'='1' || (select distinct  filter from t_Wage_Status where companyid = '43f00833-586d-4f53-81c7-1e10f528ca9c' and year = 2012 and month = 10)一样查不出数据
      

  7.   


    额...'1'='1' ||  缺一个 and 符号
    你上面那样写 意思是把 '1' 和 '1' || (select distinct  filter from t_Wage_Status where companyid = '43f00833-586d-4f53-81c7-1e10f528ca9c' and year = 2012 and month = 10 这个拼接的字符串比较,肯定是比较false的..