1

私は2つのテーブルを持っています: 列を持つ位置: id,x,y,entityID 列を持つ速度: id,speedX,speedY,entityID

一部のエンティティのみが速度を持っているため、位置と速度の間に何らかの内部結合が必要です。

私の問題は、1 つのクエリで Position.entityID = Speed.entityID の Speed テーブルから速度で位置を更新したいことです。

お願いします、いくつか SQL のことを教えてくれませんか?

ありがとう!

4

1 に答える 1

2

結合による更新の典型的なアプローチ:

update Position 
  set x=(select speedx from Speed s where s.entityID=Position.entityID),
  set y=(select speedy from Speed s where s.entityID=Position.entityID)
where exists (select 1 from Speed where s.entityID=Position.entityID)

パフォーマンス バイス これは最適ではありません (内部クエリ)。シナリオに適合する場合は、「INSERT OR REPLACE」を評価することもできます。

于 2013-09-20T11:20:55.097 に答える