我們在下面有一個查詢。它在根據日期搜索最新培訓的地方工作得很好。我想了解爲什麼我們要把B1.driverTrainingDate < B2.driverTrainingDate而不是其他方式,而且B2.driverID IS NULL。是否有任何其他選項來改善此查詢?試圖瞭解和優化mysql查詢
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)
請用'EXPLAIN SELECT'結果編輯您的答案 – Kermit 2013-02-14 17:50:04
您想如何編寫'B1.driverTrainingDate
fvu
2013-02-14 17:51:35
@fvu我需要根據特定駕駛員的培訓列表獲取最新的培訓日期。 – biz14 2013-02-14 17:54:50