Let’s say you have raw data as so:
Id Counter Ident
----------- ----------- -----
1 1 A
2 2 A
3 1 A
4 3 B
5 3 B
6 2 A
7 1 A
8 4 C
9 2 C
10 1 B
11 1 B
12 4 B
And you want to group by the Ident field, but
only contiguous blocks. So you want to display
the following:
Counter Ident
----------- -----
4 A
6 B
3 A
6 C
6 B
Naturally one can’t use GROUP BY, because this would
aggregate multiple A’s and B’s.
Answers on a postcard!
====
CREATE TABLE [dbo].[Test](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Counter] [int] NOT NULL,
[Ident] [varchar](3)
COLLATE Latin1_General_CI_AS NOT NULL,
CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
1 Comments:
At April 21, 2009 8:42 AM ,
Mark said...
My solution: http://snippets.dzone.com/posts/show/7232
Post a Comment
<< Home