1, 在表中加主键 ID (本身应有一个主键吧?)2、 create table #Temp (PKID int identity(1,1), ID int ) do while (exists( select * from tableName where ID not in (select ID from #temp))) begin insert #temp select min(id) id FROM tableName where ID not in ( select ID from #temp) group by partionNO end --此时其顺序已经保存在表#temp中了select a.PartNO, a.Name, from tableName a, #temp b where a.ID = b.ID order by b.PKID大至思路是这样,我没调试脚本 :)
1, 在表中加主键 ID (本身应有一个主键吧?)2、 create table #Temp (PKID int identity(1,1), ID int ) do while (exists( select * from tableName where ID not in (select ID from #temp))) begin insert #temp(ID) select min(id) id FROM tableName where ID not in ( select ID from #temp) group by partionNO end --此时其顺序已经保存在表#temp中了select a.PartNO, a.Name, from tableName a, #temp b where a.ID = b.ID order by b.PKID大至思路是这样,我没调试脚本。
数据为: aa 3
bcd 1
r 2
ar 4
. .
. .
. .数据有很多 我想要的结果是
PARTNO 列显示顺序为
1,2,3...n,1,2,3...n,1,2,3...n
不是
1,2,3...n?
2.利用游标语法来替换C语言中的index问题.但是会有很大的问题.
效率问题--将集合操作转化为表的操作,关系代数中不直接支持这样的演算,而且游标性能很低建议将数据集取出来,在前台程序中进行控制输出.
create table #Temp
(PKID int identity(1,1),
ID int )
do while (exists( select * from tableName where ID not in (select ID from #temp)))
begin
insert #temp
select min(id) id FROM tableName
where ID not in ( select ID from #temp)
group by partionNO
end
--此时其顺序已经保存在表#temp中了select a.PartNO, a.Name,
from tableName a, #temp b
where a.ID = b.ID
order by b.PKID大至思路是这样,我没调试脚本 :)
create table #Temp
(PKID int identity(1,1),
ID int )
do while (exists( select * from tableName where ID not in (select ID from #temp)))
begin
insert #temp(ID)
select min(id) id FROM tableName
where ID not in ( select ID from #temp)
group by partionNO
end
--此时其顺序已经保存在表#temp中了select a.PartNO, a.Name,
from tableName a, #temp b
where a.ID = b.ID
order by b.PKID大至思路是这样,我没调试脚本。
还是
NAME列:aa,b,..