我有一个员工表,其中的字段是:
first_name, last_name, hire_date, salary, department_id, department_name
, 等等。
我打算找出EMPLOYEE1 and EMPLOYEE2
、 那么EMPLOYEE2 and EMPLOYEE3
、 等等 之间的雇佣日期差异。
我必须在 sql 中编写一个查询来显示员工的名字和雇用日期差异
我有一个员工表,其中的字段是:
first_name, last_name, hire_date, salary, department_id, department_name
, 等等。
我打算找出EMPLOYEE1 and EMPLOYEE2
、 那么EMPLOYEE2 and EMPLOYEE3
、 等等 之间的雇佣日期差异。
我必须在 sql 中编写一个查询来显示员工的名字和雇用日期差异
要在 Microsoft SQL 2012 中使用天(用年、小时等代替天)来查找日期之间的差异:
Select datediff(day, HireDate, EndDate)
From Employee1
Since you've still not mentioned what RDBMS you are using i'll start with SQL-Server:
WITH x
AS (SELECT first_name,
last_name,
hire_date,
salary,
department_id,
department_name,
hireNum=Row_number()
OVER(
ORDER BY hire_date)
FROM dbo.employee)
SELECT DiffDays=Datediff(day, x.hire_date, x2.hire_date),
first_name,
last_name,
hire_date,
salary,
department_id,
department_name
FROM x
INNER JOIN x x2
ON x.hirenum = x2.hirenum + 1