当前位置: 代码迷 >> Oracle开发 >> 把NAME列中雷同的姓名的ID改成一个
  详细解决方案

把NAME列中雷同的姓名的ID改成一个

热度:6   发布时间:2016-04-24 07:13:09.0
把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
  相关解决方案