这是我的代码:
SELECT EMPNO, ENAME, JOB, to_char(HIREDATE, 'Month YYYY'), SELECT
EXTRACT(YEAR FROM SYSDATE) - EXTRACT(YEAR FROM HIREDATE) FROM EMP;
CASE
WHEN DEPTNO = 10 THEN 'Accounting'
WHEN DEPTNO = 20 THEN 'Research'
WHEN DEPTNO = 30 THEN 'Sales'
WHEN DEPTNO = 40 THEN 'Operations'
END AS DEPT
FROM EMP;
我可以在另一个命令窗口中单独使用select extract函数,但在此查询中似乎无法使其正常工作。在添加日期减法部分之前,查询成功。抱歉,菜鸟问题我对SQL还是很陌生。任何帮助将不胜感激
答案 0 :(得分:0)
看来您不需要额外的选择
SELECT EMPNO, ENAME, JOB, to_char(HIREDATE, 'Month YYYY'),
EXTRACT(YEAR FROM SYSDATE) - EXTRACT(YEAR FROM HIREDATE),
CASE
WHEN DEPTNO = 10 THEN 'Accounting'
WHEN DEPTNO = 20 THEN 'Research'
WHEN DEPTNO = 30 THEN 'Sales'
WHEN DEPTNO = 40 THEN 'Operations'
else null
END AS DEPT
FROM EMP;