我们在下面有一个查询。它在根据日期搜索最新培训的情况下运行良好。我想了解为什么我们放 B1.driverTrainingDate< B2.driverTrainingDate 而不是相反,而且 B2.driverID 也为空。是否有任何其他选项可以改进此查询?
SELECT driver.driverID,b.driverTrainingDate
FROM driver
LEFT JOIN (
SELECT B1.*
FROM dTraining AS B1
LEFT JOIN dTraining AS B2
ON B1.driverID = B2.driverID
AND B1.cTrainingID = B2.cTrainingID
AND B1.driverTrainingDate< B2.driverTrainingDate
WHERE B1.cID=".$cTID." And B2.driverID IS NULL) as b
ON ( driver.driverID= b.driverID)