I've been trying display all employees with their 1 or more year experience , but it keeps showing all , i'm using DATEDIFF(YEAR,Hired_Date,GETDATE()) >= 1
in where clause but even with less that a yr experience, it keeps showing.
员工人数
ID Hired_Date
001 2018-05-01
002 2018-03-01
003 2020-05-01
004 2019-12-05
005 2017-03-01
显示日历年的差异。因此2019-12-31和2020-01-01相隔1个日历年。
Depending on how precise you need it to be, you should probably use
month
instead ofyear
.您的查询存在的问题是DATEDIFF给出了diff的天数,您可以将其除以365,将其转换为年。请执行以下查询:
SELECT ID, Hired_Date WHERE (DATEDIFF(now(), hire_date))/365>=1;
In your Query you are using
EmpStartDate
instead ofHired_Date
.