日期:2014-05-17  浏览次数:20752 次

把NAME列中相同的姓名的ID改成一个
本帖最后由 kongpahuixiao 于 2012-12-18 17:12:11 编辑
如图
让张三的STUID为1,李四的STUID为2,王五的为3等等
------解决方案--------------------
with test as (
select 'a' as thename,'english' as subject,'90' as thescore,'1' as stuid from dual
union all
select 'b' as thename,'english' as subject,'90' as thescore,'2' as stuid from dual
union all
select 'c' as thename,'english' as subject,'90' as thescore,'3' as stuid from dual
union all
select 'a' as thename,'english' as subject,'90' as thescore,'4' as stuid from dual
union all
select 'b' as thename,'english' as subject,'90' as thescore,'5' as stuid from dual
union all
select 'c' as thename,'english' as subject,'90' as thescore,'6' as stuid from dual
union all
select 'a' as thename,'english' as subject,'90' as thescore,'7' as stuid from dual
union all
select 'b' as thename,'english' as subject,'90' as thescore,'8' as stuid from dual
)
select thename,
       subject,
       thescore,
       min(stuid) keep(DENSE_RANK first ORDER BY stuid) over(partition by thename) as stuid
  from test