在'Emplyoee'表中有两个字段 - JoinDate和EmployeeName。
Emplyoee表中包含的所有数据如下:
JoinDate | EmployeeName
------------------------
02-12-2009 Vijay
03-12-2009 Binoy
03-12-2009 Rahul
我的选择查询如下:
SELECT DISTINCT JoinDate,EmployeeName FROM Emplyoee
我得到的结果如下:
JoinDate | EmployeeName
------------------------
02-12-2009 Vijay
03-12-2009 Binoy
03-12-2009 Rahul
但我需要的结果如下:
JoinDate | EmployeeName
------------------------
02-12-2009 Vijay
03-12-2009 Binoy(first employee joined on this date)
答案 0 :(得分:0)
这将选择在每个日期加入的第一个按字母顺序的员工:
SELECT DISTINCT mydates.JoinDate,
(SELECT TOP 1 EmployeeName FROM Employee e2 WHERE e2.JoinDate=mydates.JoinDate ORDER BY EmployeeName)
FROM Employee mydates