簡體   English   中英

如何從select子查詢中存儲多個值

[英]How to store multiple values from select subquery

嗨,我在以下查詢中遇到問題:

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

當只有一個鍵時,上面的查詢工作正常。 但是,如果有多個鍵,則此查詢不起作用。 如何從select子查詢中存儲多個值? 時間列也可以是多個。 我是sql的新手。 請指導。 提前致謝。

使用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)

請嘗試以下方法:

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) 

根據要求,您還可以使用派生表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM