-1

有两个表 - 一个包含员工详细信息,另一个包含订单详细信息。

如何查找在特定日期未下订单的员工姓名?

我正在使用左外连接,我的代码是这样的

SELECT 
    emp.FirstName+' '+emp.LastName AS 'FullName', emp.employeeid 
FROM Employee emp
    INNER JOIN Orders oON emp.EmployeeID=o.EmployeeID
WHERE 
    o.OrderDate NOT IN  (SELECT o.OrderDate FROm Orders o WHERE o.OrderDate='4/4/1997')
GROUP BY 
    emp.FirstName+' '+emp.LastName, emp.employeeid

但问题是它会占用列表中的所有人员。

4

3 回答 3

3
SELECT emp.FirstName+' '+emp.LastName AS 'FullName', emp.employeeid 
FROM Employee emp LEFT JOIN Orders o 
ON emp.EmployeeID=o.EmployeeID And o.OrderDate='4/4/1997'
where o.EmployeeID is null 
GROUP BY emp.FirstName+' '+emp.LastName, emp.employeeid

试试这个。应该管用。并评论答案,因为我无法在本地测试它......

于 2012-07-24T07:26:57.930 回答
1

一种方法是使用不存在

SELECT  
    emp.FirstName+' '+emp.LastName AS 'FullName', emp.employeeid  
FROM Employee emp 
where not exists
    (select * from Orders o ON where emp.EmployeeID=o.EmployeeID 
        and  o.OrderDate='4/4/1997' 
    )
于 2012-07-24T07:20:03.073 回答
0
SELECT FirstName + ' ' + LastName AS 'FullName', 
       employeeid 
FROM Employee
where EmployeeID not in (select EmployeeID 
                         from Orders 
                         where OrderDate = '1997-04-04')
于 2012-07-24T07:16:31.203 回答