2013-07-31 57 views
1

嗨,我有下面的查詢問題存儲:如何將多個值從選擇的子查詢

Update tbl 
set somecol = somecol 
Where Key = (select key 
      from tbl 
      group by key 
      having count(*) > 1) 
    and Time = (select max(time) from tbl) 

上述查詢工作正常時,只有一個密鑰。但是,如果有多個鍵比這個查詢不起作用。如何從選擇子查詢存儲多個值?時間列也可以是多個。我是新來的sql。請指導。提前致謝。

回答

3

使用IN斷言:

Update tbl 
set somecol = somecol 
Where Key in (select key 
      from tbl 
      group by key 
      having count(*) > 1) 
    and Time = (select max(time) from tbl) 
1

嘗試以下操作:

Update tbl 
set somecol = somecol 
Where Key in (select key 
      from tbl 
      group by key 
      having count(*) > 1) 
    and Time in (select max(time) from tbl) 

根據要求,你也可以使用派生表。