假设我使用int Page,int Section和int ID标识字段创建一个表,其中页面字段的范围为1到8,部分字段的范围为1到30。现在让我们说,两个记录有重复的页面和部分。我怎么能重新编号这两个记录,以便页面和部分编号的顺序是连续的?简单SQL:如何计算集合中重复项的唯一连续数字?
select page, section
from #fun
group by page, section having count(*) > 1
示出了重复:
page 1 section 3
page 2 section 3
页面1和部分4和第2页第4丢失。有没有一种方法不使用游标来查找和重新编号SQL 2000中不支持Row_Number()的位置?
这ROWNUM下面的行程产生相同数量作为部分:
select page, section,
(select count(*) + 1
from #fun b
where b.page = a.page and b.section < a.section) as rownum
from #fun a
我可以创建中具有值的1到100枢轴表,但我会加入反对?
我想要做的是这样的:
update p set section = (expression that gets 4)
from #fun p
where (expression that identifies duplicate sections by page)
重复总是每页最高编号的部分?我们可以肯定,例如,数据集中没有(page = 1,section = 4)?如果重复的“部分”是30,我们是否需要增加“页面”? – pilcrow 2011-05-19 04:06:10
+1,想知道是否有办法做到这一点没有光标,没有'ROW_NUMBER' – AakashM 2011-05-19 06:51:24