我希望在1997年1月25日之前的3天中,将没有销售的员工出售给来自“美国”的客户。
订单表
OrderID CustomerName EmployeeName Orderdate
10248 C1 E1 1997-01-25 00:00:00:000
10249 C2 E3 1997-0-24 00:00:00:000
10250 C3 E2 1997-01-23 00:00:00:000
10251 c4 e5 1997-01-22 00:00:00:000
10251 c5 e4 1997-01-23 00:00:00:000
雇员
EmployeeID Emp_name
1 E1
2 E2 and so on till e5
顾客
CustomerID Country
C1 USA
C2 UK
C3 Brazil
C4 UK
C5 USA
所需结果
EmployeeID
e2
e3
e5
查询已尝试
select EmployeeID
from Employees e1
where employeeid not in
(
select o.EmployeeID
from orders o
full join customers c on o.CustomerID=c.CustomerID
where c.Country = 'USA'
and o.RequiredDate >= dateadd(day,-3, '1997-01-25')
)
- 从e1到e5共有员工。
- e1在1997年1月25日为客户c1服务。 C1来自美国
- e4在1997年1月23日(1997年1月25日之前的3天内)为客户c4提供了服务,而c4来自美国。
- 因此,从员工总数列表中获取不在e1和e4中的员工列表。
但是我得到空的结果,因为没有行。任何人都可以帮忙。 (这只是一个样本):罗斯文数据库中的数据。我刚刚创建了示例数据,以防有人没有罗斯文数据库
完全基于您“提供”的表数据,问题在于您正在寻找整数的Employee ID,而子查询返回的是雇员姓名列表。因此,如果您这样修改它,您将获得正确的答案: