无法绑定多部分标识符 "t1.LogTime"。我错过了什么?

The multi-part identifier "t1.LogTime" could not be bound. What I missed?

我需要日志中的一些数据,例如 XY 天谁开车。

查询是:

SELECT
t1.LogTime, 
t1.UnitId, 
t1.Alarm, 
t1.Speed, 
t1.Km, 
t1.GPSVisibleSats, 
t1.InputMask, 
t1.AX0, 
t1.Country, 
t1.City, 
t1.Street,
t3.Name
FROM dbo.t_log AS t1
LEFT JOIN
  (SELECT TOP 1 * FROM dbo.t_driver_log AS v1 WHERE v1.UnitId = '391.03.016' AND t1.LogTime BETWEEN v1.StartTime AND v1.StopTime) AS t2 ON ( t1.UnitId = t2.UnitId )
LEFT JOIN dbo.t_driver AS t3 ON ( t2.DriverId = t3.DriverId ) 
WHERE t1.UnitId = '391.03.016' AND t1.LogTime BETWEEN '2016-10-04 00:00:00' AND '2016-10-04 23:59:59'

这些家伙怎么了?错误来自子查询。

SQL Schema

子查询问题 由于您不能直接在子查询中直接访问 t1.LogTime,请尝试更新脚本,尝试将 AND t1.LogTime BETWEEN t2.StartTime AND t2.StopTime 这个条件移动到 JOIN

...
FROM dbo.t_log AS t1
LEFT JOIN
(SELECT TOP 1 * 
 FROM dbo.t_driver_log AS v1 
 WHERE v1.UnitId = '391.03.016'
) AS t2 ON ( t1.UnitId = t2.UnitId  AND t1.LogTime BETWEEN t2.StartTime AND t2.StopTime)
LEFT JOIN dbo.t_driver AS t3 ON ( t2.DriverId = t3.DriverId ) 
WHERE t1.UnitId = '391.03.016' AND t1.LogTime BETWEEN '2016-10-04 00:00:00' AND '2016-10-04 23:59:59'