-2
我目前正在使用一個大的SELECT語句,它提供了我需要從多個表中刪除的所有信息(性能不是那麼糟糕),但是我想要做的僅僅是每個testcase.foreignID顯示一個條目並且variant.idVariant,具有最高計劃的測試集日期如何選擇只與每個TestcaseID和VariantID MAX(日期)?
我試過Group By,但沒有成功。
SELECT testcase.foreignID AS TcID, testcase.foreignOrderNr AS TcOrderNr,testcase.Name AS TcName,variant.Name AS Variant,device.Supplier,plannedtestset.foreignID AS TestSetID,plannedtestset.Date,tester.Name AS Tester,testcaseexecution.Result,testcaseexecution.Comment,sw_version.Version AS SW_Version,hw_version.Version AS HW_Version,testcase.ABP,testtype.Name AS TestType,project.Name AS Project
FROM mydb.testcaseexecution
INNER JOIN mydb.testcase
ON testcaseexecution.Testcase_idTestcase=testcase.idTestcase
INNER JOIN mydb.plannedtestset
ON testcaseexecution.PlannedTestSet_idPlannedTestSet=plannedtestset.idPlannedTestSet
INNER JOIN mydb.device
ON plannedtestset.Device_idDevice=device.idDevice
INNER JOIN mydb.variant
ON device.Variant_idVariant=variant.idVariant
INNER JOIN mydb.tester
ON plannedtestset.Tester_idTester=tester.idTester
INNER JOIN mydb.sw_version
ON plannedtestset.SW_Version_idSW_Version=sw_version.idSW_Version
INNER JOIN mydb.testtype
ON plannedtestset.TestType_idTestType=testtype.idTestType
INNER JOIN mydb.project
ON plannedtestset.Project_idProject=project.idProject
INNER JOIN mydb.hw_version
ON device.HW_Version_idHW_Version=hw_version.idHW_Version
WHERE plannedtestset.Date In(
SELECT Max(plannedtestset.Date)
FROM mydb.plannedtestset
GROUP BY testcase.idTestcase
)
如何將上述內容作爲內部查詢加入,並且在排序或選擇MAX()之後,外部查詢只選擇一條記錄(即「LIMIT 1」)? –
FDavidov
我不太明白,你介意給一個SELECT語句的例子嗎? – r00flr00fl
請顯示樣本數據。 –