如果沒有相同的設備和測試中合格後失敗的可能性,只是使用與最大的時間一個簡單的內部查詢:
select Device, Test, Pass, TimeStamp from table
join (
select Device, Test, max(Timstamp) as TimeStamp from table group by 1,2) t1
on t1.Device=table.Device and t1.Test=table.Test and t1.TimeStamp =table.TimeStamp
如果有內傳球后失敗的可能性相同的設備和測試,你只需要通過,需要2個內部連接:
select Device, Test, Pass, TimeStamp from table join (
select Device, Test, Pass, max(TimeStamp) as TimeStamp from table
join (
select Device, Test, max(Pass) as Pass from table group by 1,2) t1
on t1.Device=table.Device and t1.Test=table.Test and t1.Pass =table.Pass
group by 1,2,3) t2
on t2.Device=table.Device and t2.Test=table.Test and t2.Pass =table.Pass and t2.TimeStamp =table.TimeStamp
你到目前爲止嘗試了什麼? – mucio
@mucio一個工會所有自我與where子句,無法引用我的表別名。一堆不起作用的東西。 –