日期:2014-05-18  浏览次数:20430 次

求一SQL 指令写法
如有一表
--
A
B
B
B
C
C
D
想得到如可结果(过滤重复行加一列序号)
----
A       1
B       2
C       3
D       4


------解决方案--------------------
--例子--
create table tab(c varchar(10))
insert tab
select 'A '
union all select 'B '
union all select 'B '
union all select 'B '
union all select 'C '
union all select 'C '
union all select 'D '


select id=(select count(1) from (select c from tab group by c) a where c <=t.c),c from (select c from tab group by c) t


drop table tab