我希望employee numbers
和start dates
的所有员工start dates
等于最早的日期。
我知道这是错的。但只是写作来展示我想要的东西。
SELECT start_date, employee_no
FROM [employees]
WHERE (start_date = MIN(start_date))
答案 0 :(得分:7)
你很亲密!
SELECT start_date, employee_no
FROM [employees]
WHERE start_date = (SELECT MIN(start_date) FROM employees)
答案 1 :(得分:3)
我会使用通用表达式表(CTE)来执行此操作。这就像创建一个临时表。
;with EmpInfo as
(
SELECT start_date, employee_no, MIN(start_date) OVER () as MinStartDate
FROM [employees]
)
SELECT start_date, employee_no FROM EmpInfo WHERE start_date = MinStartDate
的Microsoft网页
答案 2 :(得分:0)
这样做:
SELECT start_date, employee_no
FROM [employees]
WHERE start_date = (select MIN(start_date) from [employees])
答案 3 :(得分:0)
SELECT start_date, employee_no
FROM [employees]
WHERE start_date = (SELECT MIN(start_date) FROM [employees])