将2个查询组合成1个查询

时间:2013-10-07 18:01:53

标签: sql

如何将第一个查询的结果与第二个查询结合起来,EMPLID表和Z_EMP_YAN表的Z_OPRDEFN列匹配?

select b.OPRID
from Z_EMP_BENFT a, PSOPRDEFN b
WHERE a.EMPLID = b.EMPLID
AND A.Z_PEND_COVER = 'Y'
AND OPRID LIKE 'ZZ%'

select EMPLID from z_emp_yan where z_yan_action_id = 1

2 个答案:

答案 0 :(得分:3)

上一篇文章没有什么问题,我更喜欢使用Joins

select b.oprid 
from ps_z_emp_benft a
    join psoprdefn b on a.emplid = b.emplid 
    join ps_z_emp_yan c on a.emplid = c.emplid 
where A.z_pend_cover = 'Y' 
    and oprid LIKE 'ZZ%' 
    and c.z_yan_action_id = 1 

答案 1 :(得分:2)

试试这个

SELECT b.oprid 
FROM   ps_z_emp_benft a, 
       psoprdefn b, 
       ps_z_emp_yan c 
WHERE  a.emplid = b.emplid 
       AND a.emplid = c.emplid 
       AND A.z_pend_cover = 'Y' 
       AND oprid LIKE 'ZZ%' 
       AND c.z_yan_action_id = 1