读书人

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

发布时间: 2012-12-31 11:57:52 作者: rapoo

把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

读书人网 >oracle

热点推荐