试图理解和优化mysql查询

时间:2013-02-14 17:48:56

标签: mysql

我们在下面有一个查询。它在根据日期搜索最新培训的情况下工作正常。我想了解为什么我们把B1.driverTrainingDate< B2.driverTrainingDate而不是相反,B2.driverID也是NULL。还有其他选项可以改进此查询吗?

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)

1 个答案:

答案 0 :(得分:0)

我认为这是打算返回完整记录之前但具有空驱动程序ID的培训日期。

如果数据模式甚至存在,那么“反过来”将意味着......之后。