1
Timezones
---------
-AreaCode varchar
-Timezone varchar

Contacts
--------
-Phone    varchar
-Timezone varchar

Timezone連絡先テーブルを除いてすべてが入力されているので、各電話番号のタイムゾーンを検索して連絡先を更新します。これが私がやろうとしたことですがMySQL

エラー1242サブクエリが複数の行を返す

タイムゾーン(0、-1、-2、-3、-4、-5)ごとに、次の更新を実行します。

update contacts 
set contacts.timezone = '-1' 
where left(contacts.phone,3) = (Select timezones.areacode 
                                from timezones 
                                where timezones.timezone = '-1');
4

4 に答える 4

2

サブクエリは複数の行を返します。この問題を処理するには、「=」を「IN」に置き換えるだけです。

update contacts 
set contacts.timezone = '-1' 
where left(contacts.phone,3) in (Select timezones.areacode 
                                from timezones 
                                where timezones.timezone = '-1');
于 2012-08-28T16:35:20.367 に答える
0

更新時に内部結合を試すか、サブクエリを試してください。

update contacts 
set contacts.timezone = '-1' 
where left(contacts.phone,3) in (Select timezones.areacode 
                                from timezones 
                                where timezones.timezone = '-1');
于 2012-08-28T16:33:58.993 に答える
0

次のような部分を変更します:...。

where left(...) in (select ...... ) 
于 2012-08-28T16:34:15.777 に答える
0

問題は、タイムゾーンにtを持つ行が複数ある可能性があることです。imezone column = '-1'

Joinここで使用できます

update contacts join timezones on left(contacts.phone,3) = timezones.areacode and timezones.timezone = '-1'
set contacts.timezone = '-1';

市外局番と電話が一致し、その場合は次のように更新されます'-1'

于 2012-08-28T16:34:46.357 に答える