我有这样的查询
SELECT EDR.DEPT_ID AS DEPT_ID,
EMP.EMPLOYEE_ID AS EMPLOYEE_ID,
ELD.LOAN_ID AS LOAN_ID,
ELD.LOAN_STATUS AS LOAN_STATUS
FROM EMP_DEPT_REL EDR
INNER JOIN EMPLOYEE_MANUAL EMP
ON EDR.EMPLOYEE_ID = EMP.EMPLOYEE_ID
LEFT OUTER JOIN EMPLOYEE_LOAN_DETAIL ELD
ON ELD.LOAN_ID = EMP.LOAN_ID
AND ELD.DISPLAY_FLAG = 'Y'
WHERE EDR.DEPT_ID IN ('123');
我想从部门中关联的所有员工获取数据,我将其作为输入传递。
我需要的是,
需要获取在特定部门贷款的员工的数据。如果员工有外部贷款,我们需要显示贷款明细。(DISPLAY_FLAG =' Y')如果是组织提供的内部贷款,它将在Employee_loan_detail中,并标记为DISPLAY_FLAG =" N"
EMPLOYEE_LOAN_DETAIL
<table>
<tr><th>EMPLOYEE_ID</th><th>LOAD_ID</th><th>DISPLAY_FLAG</th><tr>
<tr><td>123</td><td>50</td><td>Y</td></tr>
<tr><td>456</td><td>51</td><td>N</td></tr>
<table>
emp_dept_rel
<table>
<tr><th>EMP_ID</th><th>DEPT_ID</th><tr>
<tr><td>123</td><td>987</td></tr>
<tr><td>456</td><td>987</td></tr>
<tr><td>789</td><td>987</td></tr>
<table>
employee_manual
<table>
<tr><th>EMPLOYEE_ID</th><th>LOAD_ID</th><th>DEPT_ID</th><tr>
<tr><td>123</td><td>50</td><td>987</td></tr>
<tr><td>456</td><td>51</td><td>987</td></tr>
<tr><td>789</td><td></td><td>987</td></tr>
<table>
答案 0 :(得分:0)
试试这个:
SELECT
EDR.DEPT_ID AS DEPT_ID,
EMP.EMPLOYEE_ID AS EMPLOYEE_ID,
ELD.LOAN_ID AS LOAN_ID,
ELD.LOAN_STATUS AS LOAN_STATUS
FROM EMPLOYEE_MANUAL EMP
INNER JOIN EMP_DEPT_REL EDR
ON EDR.EMPLOYEE_ID = EMP.EMPLOYEE_ID
LEFT OUTER JOIN EMPLOYEE_LOAN_DETAIL ELD
ON ELD.LOAN_ID = EMP.LOAN_ID
WHERE EDR.DEPT_ID IN ('123') AND ELD.DISPLAY_FLAG = 'Y';