34,593
社区成员
发帖
与我相关
我的任务
分享
select distinct 款号,工种,自动编号=row_number() over(order by 款号,工种) from tb
--使用临时表完成
select id = identity(int ,1,1) , distinct 款号,工种 into tmp from tb
select * from tmp
--直接查询
select n.* , id = (select count(1) from
(
select distinct 款号,工种 from tb
) m where 款号 < n.款号 or (款号 = n.款号 and 工种 < n.工种)) + 1
from
(
select distinct 款号,工种 from tb
) n
--使用临时表完成
select id = identity(int ,1,1) , distinct 款号,工种 into tmp from tb
select * from tmp
--直接查询
select n.* , id = (select count(1) from
(
select distinct 款号,工种 into tmp from tb
) m where 款号 < n.款号 or (款号 = n.款号 and 工种 < n.工种)) + 1
from
(
select distinct 款号,工种 into tmp from tb
) n
select identity(int,1,1) as ID,a.* into # from (select distinct 款号,工种 from tb) a
select * from #
select id = identity(int ,1,1) , distinct 款号,工种 into tmp from tb
select * from tmp