0

同じテーブルの別の列の最小値に基づいて、テーブルの列を更新したいと考えています。

例えば。

JobPositonId | JobPositonName | JobDescriptionId | ContactId
1            | 1              | 1                | 1
2            | 1              | 1                | 0
3            | 1              | 1                | 0

ContactId が 0 で、JobPositionId が最も低い場合は、ContactId を 1 に更新します。

4

1 に答える 1

1

私はこれがうまくいくと思います:

update jobTable
   set contactid = 1
 where jobPostitionId in (select pos from (select min(jobPositionId) as pos from jobTable where contactId = 0) as subtable);

ここで説明されているものと同様のハックです(http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in-mysql/)。

于 2010-08-24T19:12:16.813 に答える