首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

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

2012-12-31 
把NAME列中相同的姓名的ID改成一个让张三的STUID为1,李四的STUID为2,王五的为3等等[解决办法]with test as

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

让张三的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

热点排行