Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 显示在公司中完成相同数量服务的员工姓名_Sql_Sql Server - Fatal编程技术网

Sql 显示在公司中完成相同数量服务的员工姓名

Sql 显示在公司中完成相同数量服务的员工姓名,sql,sql-server,Sql,Sql Server,我得到了员工姓名和服务年限,但我不知道如何提取与您的服务年限相同的员工姓名: select Ename ,year(getdate())- year(Hiredate) LenghtOfService from Employee 这个问题很不清楚,至少对我来说是这样。你能分享一些样本数据和你试图从这个样本中得到的结果吗?我想要有相同经验的员工姓名1000 Xavior London 1030 2009-02-21 54000 10 1010 John India 1060 2008-04-1

我得到了员工姓名和服务年限,但我不知道如何提取与您的服务年限相同的员工姓名

select Ename ,year(getdate())- year(Hiredate) LenghtOfService 
from Employee

这个问题很不清楚,至少对我来说是这样。你能分享一些样本数据和你试图从这个样本中得到的结果吗?我想要有相同经验的员工姓名1000 Xavior London 1030 2009-02-21 54000 10 1010 John India 1060 2008-04-12 49000 30 1020 Peter India 1090 2009-02-21 74000 401030 Smith London 1060 2003-05-23 100000 301040 Paul Stamford 1030 2010-10-10 38000 40编辑问题添加一些示例数据,期望的结果会有所帮助。
select e.*
from (select e.*, 
             count(*) over (partition by datediff(year, e.hiredate, getdate())) as LenghtOfService
      from Employee e
     ) e
where LenghtOfService > 1;