我无法在这里找出错误的位置。据我所知,一切看起来都是正确的:
SELECT a.department_name
FROM department a
OUTER JOIN (SELECT department_id,
NVL((TO_CHAR(MAX(salary + commission)), '$9,990.00'), '$0.00') as "Maximum Total Pay",
NVL((TO_CHAR(MAX(hire_date)), 'DD-MON-YYYY'), '01-JAN-3000') as "Maximum Hire Date",
NVL((TO_CHAR(MIN(hire_date)), 'DD-MON-YYYY'), '01-JAN-3000') as "Minimum Hire Date",
COUNT(*) AS NUMBER_OF_EMPLOYEES
FROM employee c
WHERE employee_id IS NOT NULL
GROUP BY c.department_id)
ON a.department_id = c.department_id
ORDER BY a.department_name;
我收到SQL命令未正确结束的错误。任何帮助将不胜感激。
谢谢!
编辑:我无法选择两个正确的答案,因为这些都有助于我找到正确的解决方案。感谢所有帮助过的人。答案 0 :(得分:1)
我想,空值可能来自您的子查询,但不是来自部门,因此请使用LEFT
OUTER JOIN。
但主要问题是由于对
的禁忌 NVL((TO_CHAR(MAX(hire_date)), 'DD-MON-YYYY'), '01-JAN-3000')
陈述,
两种用途:
NVL(TO_CHAR(MAX(hire_date), 'DD-MON-YYYY'), '01-JAN-3000')
取而代之的是,从左侧删除第1和第5个paranthesis。
答案 1 :(得分:0)
您似乎需要为要加入的子查询设置别名,并添加关键字{1, 2, 3, 4}
:
LEFT
我将其称为SELECT a.department_name
FROM department a
LEFT OUTER JOIN (SELECT department_id,
NVL((TO_CHAR(MAX(salary + commission)), '$9,990.00'), '$0.00') as "Maximum Total Pay",
NVL((TO_CHAR(MAX(hire_date)), 'DD-MON-YYYY'), '01-JAN-3000') as "Maximum Hire Date",
NVL((TO_CHAR(MIN(hire_date)), 'DD-MON-YYYY'), '01-JAN-3000') as "Minimum Hire Date",
COUNT(*) AS NUMBER_OF_EMPLOYEES
FROM employee c
WHERE employee_id IS NOT NULL
GROUP BY c.department_id) c1
ON a.department_id = c1.department_id
ORDER BY a.department_name;
,以便您可以注意到别名。