2016-09-30 41 views
0

我需要一些幫助來創建更新查詢。比如我有SQL更新2個表中的1個表

select:(T1- table 1, T2- tables 2, Z1 -column from table 1, Z2 Column from table 2 etc) 

Select * from T1,T2 where X1=X2 and Y1=Y2 and Z1=Z2 and Datea>=20160601 and Dateb<20160720 and B1=2 and C1=5 and D1=10 and E2 in (A+,A-, 22,33,44) 

現在我想寫它使用參數

from where 
update T1 set F1, G1 where 

如何編寫正確的條件的update

+0

你可以在你的更新中執行子查詢嗎? – mfredy

+0

例如:UPDATE TABLENAME SET F1 =(SELECT * FROM) – mfredy

+0

對不起,我寫錯了。更新應該像更新T1設置F1 = 10,G1 = 50其中 – KrzK

回答

0
update T1 set F1=10, G1=50 
where exist (Select F1, G1 
      from T1,T2 where X1=X2 
      and Y1=Y2 and Z1=Z2 
      and Datea>=20160601 
      and Dateb<20160720 
      and B1=2 
      and C1=5 
      and D1=10 
      and E2 in (A+,A-, 22,33,44)) 

您必須選擇需要在select子句中更新的列。

也試着先運行select語句,看看你是否得到你想要的結果