我試圖做到這一點query1
子查詢:更新與同桌
UPDATE temp_svn1 t set closedate=(select max(date) from temp_svn1 p where p.id=t.id
顯然MySQL不允許此類查詢。所以我想出了使用內連接的這個查詢,但是這太慢了。我怎樣才能爲此寫一個更好的查詢?或者我如何實現query 1
的邏輯?
UPDATE temp_svn1 AS out INNER JOIN (select id, close from temp_svn1 T inner join (select id as cat, max(date) as close from temp_svn1 group by cat) as in where T.id = in.cat group by id) as result ON out.id = result.id SET out.closedate = result.close
不,它沒有。以下是錯誤: '您無法在FROM子句中指定目標表'temp_svn1'進行更新' – Gaurav 2010-11-18 19:17:49
對不起,我在ms sql中進行了測試。 – 2010-11-18 19:25:20