【发布时间】:2012-02-09 15:13:08
【问题描述】:
我需要根据连续数字(N 列)和这些数字相关的相同“类别”(下面的 C 列)从表中提取连续范围。从图形上看是这样的:
N C D
--------
1 x a C N1 N2 D1 D2
2 x b ------------------
3 x c x 1 4 a d (continuous range with same N)
4 x d ==> x 6 7 e f (new range because "5" is missing)
6 x e y 8 10 g h (new range because C changed to "y")
7 x f
8 y g
9 y h
10 y i
SQL Server 是 2005。谢谢。
【问题讨论】:
-
可以通过存储过程来实现吗?
-
如果您可以访问 SQL Cookbook,这是配方 10.3。 amazon.com/Cookbook-Cookbooks-OReilly-Anthony-Molinaro/dp/… 很牵强。
-
@MattFenwick:谢谢,看起来那个recepie 可以做我需要的,在我可以咀嚼它之后。
标签: sql sql-server sql-server-2005 gaps-and-islands