2011-09-08 15 views
0

このクエリに問題があります。mysql update with join and count

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 

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

よりも小さい場合は尋ねる、グループごとの行数をカウントしたいです私たちを手伝ってくれますか?

THXのBR

答えて

0

あなたはtable2hにすることをtable2なると、あなた「realias」する副選択の結果のためのエイリアスを設定しています。その上にテーブルhaisinで結合しようとします。

他の2つの表とその表を結合できるようにするには、副選択内でisinを選択する必要があります。

0
update table1 as a 
left join (
select count(*) as 'rec' from table2 group by isin having rec<100) 
-- here you have that error 

チェックこのdoc http://dev.mysql.com/doc/refman/5.0/en/join.html

しかし、なぜあなたはTABLE1を更新している場合は結合を実行したいですか?何をしたいですか?

0

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

iは、表2に次にISIN当たり100行(両方のテーブル内のキー)未満である場合TABLE1(a.nohist)にフラグを設定することになります。

参加しない理由はありますか?

suunto