SQLサーバーテーブルには、START
行の行があり、テーブルを更新する必要があります。INSERT
はそれぞれEND
行です。選択した行に基づいてループを挿入する
select distinct transaction_id from transactions t1
where
this_status_id = 2 and that_type_id = 1
and not exists
(
select *
from transactions t2
where t2.transaction_id = t1.transaction_id
and t2.this_status_id in (1,3,4)
and t2.that_type_id = 1
)
このセレクトリターンIDのリスト(ないプライマリキー)が私は上記の選択からのIDのそれぞれをループする必要があり、同様に同じ表に挿入 :
なぜ同じIDを再挿入するのですか?なぜあなたは更新をしないのですか? – ollie
なぜループですか? 'INSERT into transactions ... [MSFT(Select into select ...構文)](https://technet.microsoft.com/en-us/library)からSELECTトランザクションID、 '終了'、1,2、getdate()FROMトランザクション/ms189872(v=sql.105).aspx)。ループは遅いです... RDBMSのセットベースの処理はずっと効率的です。 – xQbert