EmployeeID EmployeeName
0001 Mr.A
0002 Mr.A
0003 Mr.A
0004 Mr.B
0005 Mr.B
0006 Mr.B
0007 Mr.C
0008 Mr.C
0009 Mr.C
Expected Output
0001 Mr.A
0004 Mr.B
0007 Mr.c
我希望只看到第一次出现员工ID的唯一员工姓名。
答案 0 :(得分:1)
您可以使用row_number()
:
select t.*
from (select t.*,
row_number() over (partition by EmployeeName order by EmployeeId) as seqnum
from table t
) t
where seqnum = 1;
答案 1 :(得分:0)
CTE
使用ROW_NUMBER
WITH C AS(
SELECT ROW_NUMBER() OVER (PARTITION BY EmployeeName ORDER BY EmployeeId) AS Rn
,EmployeeId
,EmployeeName
)
SELECT * FROM C WHERE Rn = 1