当前位置: 代码迷 >> Sql Server >> SQL ID有关问题
  详细解决方案

SQL ID有关问题

热度:78   发布时间:2016-04-27 12:52:45.0
SQL ID问题
select distinct 1,'900',a.dsp,5,stuff (a.dsl,1,1,''),1 from jpftab b,jdstab a 
where a.dd#=90000888 order by '900',5;

想让ID4从1,2,3这样按顺序下去

id1 id2 id3 id4 id5 id6
1 900 10010003 5 5.000 1
1 900 10010004 5 5.000 1
1 900 10010005 5 5.000 1
1 900 10010007 5 5.000 1
1 900 10010009 5 5.000 1

想要的结果

id1 id2 id3 id4 id5 id6
1 900 10010003 1 5.000 1
1 900 10010004 2 5.000 1
1 900 10010005 3 5.000 1
1 900 10010007 4 5.000 1
1 900 10010009 5 5.000 1

------解决方案--------------------
SQL code
--使用identity函数select distinct 1 as id1,'900' as id2,a.dsp as id3,id4 = IDENTITY(int, 1, 1),stuff (a.dsl,1,1,'') as id5,1  as id6into #tb from jpftab b,jdstab a  where a.dd#=90000888 order by id2,id4select id1,id2,id3,id4,id5,id6 from #tb
  相关解决方案