尝试提取过去一周未评估(评分)的代理列表。我正在获取Agent_Name,但在检查评估列表时,它们的名称出现在评估列表中。
select agent.firstname + ' ' + agent.lastname Agent_Name
from dbo.agent agent
left outer join dbo.crr crr
on agent.id = crr.agentfk
left outer join dbo.evaluation eval
on crr.id = eval.crrfk
where eval.crrfk is null
and crr.localtime >= Dateadd(Day, Datediff(Day, 0, Dateadd(D, -7, Current_Timestamp)), 0);
答案 0 :(得分:0)
您需要将crr
上的条件移至on
子句:
select agent.firstname + ' ' + agent.lastname Agent_Name
from dbo.agent agent left outer join
dbo.crr crr
on agent.id = crr.agentfk and
crr.localtime >= Dateadd(Day, Datediff(Day, 0, Dateadd(D, -7, Current_Timestamp)), 0) left outer join
dbo.evaluation eval
on crr.id = eval.crrfk
where eval.crrfk is null ;
如果数据位于evaluation
,我不确定为什么需要crr
表。我的意思是,这应该做同样的事情(假设你正在使用正确的日期):
select (a.firstname + ' ' + a.lastname) as Agent_Name
from dbo.agent a left outer join
dbo.crr
on a.id = crr.agentfk and
crr.localtime >= Dateadd(Day, Datediff(Day, 0, Dateadd(D, -7, Current_Timestamp)), 0)
where crr.id is null ;