如何在ID字段中获取最大值并将该值设置为同名(列)值,动态可能吗?

时间:2015-09-28 04:34:39

标签: oracle11g oracle-sqldeveloper

Create Table Active1 (Name Varchar(20), ID int IDENTITY(1,1))

Select * from Active1

NAME                 ID                     
-------------------- ---------------------- 
vj                   102                    
vj                   103                    
vj                   104                    
vj                   105                    
vj                   106                    
swami                108                    
swami                109

需要输出

vj 106
vj 106
vj 106
vj 106
vj 106
vj 106
vj 106
vj 106
vj 106
swami 108
swami 109

(动态获取和更新值)

Update Active1 SET ID=(select MAX(ID) from Active1 where Name = (select NAME from Active1) group by name HAVING count(name) > 1);

Update Active1 SET ID=(select MAX(ID) from Active1) where name= 'select NAME from Active1' where name= 'select NAME from Active1';

1 个答案:

答案 0 :(得分:0)

这样做:

      update Active1 t set t.ID = 
          (select MAX(a.ID) from Active1 a where a.name = 'vj')
      where t.name = a.name ;