2011-09-08 44 views
0

我遇到了此查詢的問題。mysql更新加入並計數

update table1 as a 
left join (
select count(*) as 'rec' from table2 group by isin having rec<100) 
table2 as h on a.isin=h.isin 
set a.nohist='1' 

我想計算每組行,詢問他們是否計數小於100表1

的設置一個標誌,我得到送花兒給人一個錯誤:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as h on a.isin=h.isin set a.nohist='1'' at line 4 

你可以幫幫我嗎?

THX BR

回答

0

您正在設置別名的子查詢結果爲table2然後你「realias」是table2h。最重要的是,您嘗試加入ha,isin

如果您希望能夠使用其他兩個表格與該表格進行連接,則需要在子查詢中選擇isin

0

But, why do you want to perform a join if you're updating table1? What do you want to do?

我將設置一個標誌對錶1的(a.nohist)其中在表2小於然後100行每ISIN(兩個表中鍵)。

是否有沒有加入的原因?

suunto