将两个Oracle SQL查询合并为一个

我需要在一条SQL语句中合并两个查询条件。我无法在逻辑上将它们组合起来。

1) 经理批准休假的员工

select e.employee_name,r.request_from_Date,r.request_to_Date from  employee_leave e,emp_leave_request r
 where e.employee_id=r.request_from_id and e.employee_manager_id= r.request_to_id
 and r.request_Approved_date is not null
 and r.request_reject_Date is null
 and r.request_cancelled_Date is null;

2)属于经理团队的员工。

 select employee_id, employee_name, employee_email, employee_username, employee_leave_normal, employee_contact_no,employee_designation
from employee_leave a
where exists(select 1 from employee_leave b where lower(b.employee_username)=lower(:APP_USER) and a.employee_manager_id=b.employee_id);

解决方案:

你可以使用INNER JOIN来实现同样的目的.请学习什么是INNER join。此处

        SELECT     e1.*,
               e.request_from_date,
               e.request_to_date
    FROM       (
                      SELECT e.employee_id,
                             e.employee_name,
                             r.request_from_date,
                             r.request_to_date
                      FROM   employee_leave e,
                             emp_leave_request r
                      WHERE  e.employee_id=r.request_from_id
                      AND    e.employee_manager_id= r.request_to_id
                      AND    r.request_approved_date IS NOT NULL
                      AND    r.request_reject_date IS NULL
                      AND    r.request_cancelled_date IS NULL)e
    inner join
               (
                      SELECT employee_id,
                             employee_name,
                             employee_email,
                             employee_username,
                             employee_leave_normal,
                             employee_contact_no,
                             employee_designation
                      FROM   employee_leave a
                      WHERE  EXISTS
                             (
                                    SELECT 1
                                    FROM   employee_leave b
                                    WHERE  Lower(b.employee_username)=Lower(:APP_USER)
                                    AND    a.employee_manager_id=b.employee_id) e1
                      ON e.employee_id=e1.employee_id 

给TA打赏
共{{data.count}}人
人已打赏
未分类

在WebBrowser控件中避免刷新事件?

2022-9-8 16:19:36

未分类

在没有Mahapps.Metro程序集的项目中使用MetroProgressBar控件动画。

2022-9-8 16:19:38

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索