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

分组序号问题
本帖最后由 baopeng82 于 2013-11-04 09:55:41 编辑
我想实现相同的clcode、clph 的序号一样 
如下例子:
create table #b1(cjdw char(12),yscode  char(12),ysph char(12),clcode char(12),clph char(10),id int)

insert into #b1(cjdw,yscode,ysph,clcode,clph) values('000000016952','204100500766','13072+PB','207061800610','X322')
insert into #b1(cjdw,yscode,ysph,clcode,clph) values('000000016952','204100500766','13072-1+PB','207061800610','X322')
insert into #b1(cjdw,yscode,ysph,clcode,clph) values('000000016952','204100500766','13072塑料+PB','207061800610','C222')


000000016952 204100500766 13072+PB     207061800610 X322    1  
000000016952 204100500766 13072-1+PB   207061800610 X322    1  
000000016952 204100500766 13072??+PB   207061800610 C222    2  

------解决方案--------------------
select *,DENSE_RANK() over( order by clph desc) as no from #b1 


/*
000000016952 204100500766 13072+PB     207061800610 X322       NULL 1
000000016952 204100500766 13072-1+PB   207061800610 X322       NULL 1
000000016952 204100500766 13072塑料+PB 207061800610 C222       NULL 2*/