0

我是 oracle 和 sql 的新手,我想知道如何使用 Oracle ANSI 连接条件重写以下 sql 查询。

  SELECT     emp_no,
    (SELECT   emp_title
       FROM   hr_v_employee
       WHERE         organization_code LIKE
           SUBSTR (emp.depart_code, 0, 4) || '00'
             AND emp_position_code =
                (SELECT     MIN (emp_position_code)
                        FROM     hr_v_employee
                                WHERE     organization_code LIKE
                                    SUBSTR (emp.depart_code,
                                   0,
                                   4
                                   )
                 || '00'))
                 || ' '
                 || NVL (employee_deptartment, '-')
                     employee_deptartment
        FROM     employees e, employee_details o
      WHERE     emp.emp_no = o.emp_no(+)

编辑 1

这是我尝试过的,我的问题是是否可以使用联接或 ANSI 标准进行子查询?

 SELECT     emp_no,
        (SELECT   emp_title
           FROM   hr_v_employee
           WHERE         organization_code LIKE
               SUBSTR (emp.depart_code, 0, 4) || '00'
                 AND emp_position_code =
                    (SELECT     MIN (emp_position_code)
                            FROM     hr_v_employee
                                    WHERE     organization_code LIKE
                                        SUBSTR (emp.depart_code,
                                       0,
                                       4
                                       )
                     || '00'))
                     || ' '
                     || NVL (employee_deptartment, '-')
                         employee_deptartment
            FROM     employees e left outer join employee_details o (emp.emp_no = o.emp_no)
4

1 回答 1

1

除了 LEFT OUTER JOIN 缺少 ON 关键字之外,您的查询应该没问题:

SELECT emp_no,
       (SELECT emp_title
          FROM hr_v_employee
         WHERE organization_code LIKE SUBSTR(emp.depart_code,
                                             0,
                                             4) || '00'
           AND emp_position_code =
               (SELECT MIN(emp_position_code)
                  FROM hr_v_employee
                 WHERE organization_code LIKE SUBSTR(emp.depart_code,
                                                     0,
                                                     4) || '00')) || ' ' ||
       NVL(employee_deptartment,
           '-') employee_deptartment
  FROM employees e
  LEFT OUTER JOIN employee_details o
    ON emp.emp_no = o.emp_no

请注意,您的列名中有错字 - 它应该被称为employee_department而不是employee_deptartment

于 2013-08-19T10:03:32.563 回答