2010-12-08 47 views
0

table1:name |評級| stat1 | stat2
table2:name | stat3
它是論壇和網站集成,所以他們沒有正常化根據第一個表字段從另一個表中選擇SQL整個表進行更新

我需要重新計入table1用戶的評級。
rating = stat1 + stat2 + stat3
stat3table2中,其具有與table1共同的name字段。

UPDATE table1 SET rating = stat1 + stat2 + 
(SELECT stat3 FROM table2 WHERE name = [name_from_table1]) 

我如何可以插入nametable1table2選擇使用它?

回答

2

試試這個:

UPDATE table1 JOIN table2 ON table1.name=table2.name SET table1.rating=table1.stat1+table1.stat2+table2.stat3 
+0

是的,這是速度更快,然後選擇 – Qiao 2010-12-09 00:11:51

相關問題