如何找到入职不到十年的员工?

发布于 2024-12-13 02:46:01 字数 401 浏览 4 评论 0原文

我想编写一个查询来显示所有工作时间少于 10 年的员工的员工编号、姓氏、雇用日期和受雇月数。

这是我所拥有的,但 WHERE 函数有问题:

SELECT employee_id, last_name, hire_date, MONTHS_BETWEEN(SYSDATE, hire_date) "number of months employed" 
FROM employees
WHERE MONTHS_BETWEEN(SYSDATE, hire_date) <= 120;

PS:当我在没有 WHERE 函数的情况下运行它时,对于“雇用月数”,我得到 292.530207959976105137395459976105137395

请帮忙! :(

I want to write a query to display the employee number, last name, hire date, and number of months employed for all employees who have worked for less than 10 years.

This is what I have but something is wrong with the WHERE function:

SELECT employee_id, last_name, hire_date, MONTHS_BETWEEN(SYSDATE, hire_date) "number of months employed" 
FROM employees
WHERE MONTHS_BETWEEN(SYSDATE, hire_date) <= 120;

PS: when I run it without the WHERE function, for the "number of months employed" I get 292.530207959976105137395459976105137395

please help! :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我为君王 2024-12-20 02:46:01

“当我有“WHERE MONTHS_BETWEEN(SYSDATE, Hire_date) <= 120;”时
添加并运行它,我将得到找不到数据

这意味着该公司在过去十年中没有雇用任何员工。

“当我删除 'WHERE MONTHS_BETWEEN(SYSDATE, Hire_date) <=
120;`我将获得表中所有员工的结果以及
“受雇月数”,会给我
292.530207959976105137395459976105137395。 ”

您使用的表基于规范的 SCOTT.EMP 表,该表中的所有员工都是在 20 世纪 80 年代的某个时间点聘用的。

“现在,想要找到在那里工作的人数少于 10 人
年。”

您需要修改您的数据。尝试类似这样的查询。对于 ID 以奇数结尾的任何员工,它的雇用率将减少约 25 年:

update employees
set hiredate = add_months(hiredate, 300)
where mod(employee_id,2)=1
/

"when i have the "WHERE MONTHS_BETWEEN(SYSDATE, hire_date) <= 120;"
added and run it, i will get no data found "

This means the company hasn't hired any employees in the last ten years.

"and when i remove the 'WHERE MONTHS_BETWEEN(SYSDATE, hire_date) <=
120;` i will get the results of ALL employees in the table and the
"number of months employed", would give me
292.530207959976105137395459976105137395. "

You are using a table based on the cannonical SCOTT.EMP table, where all the employees were hired at some point in the 1980s.

"Now, want to find the persons who were working there less then 10
years."

You'll need to amend your data. Try something like this query. It will lop approx twenty five years off the hiredate of any employee who ID ends in an odd digit:

update employees
set hiredate = add_months(hiredate, 300)
where mod(employee_id,2)=1
/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文