当前位置: 代码迷 >> Sql Server >> 求一SQL 指令写法解决思路
  详细解决方案

求一SQL 指令写法解决思路

热度:77   发布时间:2016-04-27 17:34:39.0
求一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
  相关解决方案