ID | Value | CreatedAt | GroupNumber | Reason for new group |
---|---|---|---|---|
036a2e7d-b809-48a4-9097-05460b06f1b4 | 1 | 2019-09-13T17:08:00 | 1 | First in ID group |
036a2e7d-b809-48a4-9097-05460b06f1b4 | 2 | 2019-09-13T17:09:00 | 1 | None |
036a2e7d-b809-48a4-9097-05460b06f1b4 | 3 | 2019-09-13T17:10:00 | 1 | None |
036a2e7d-b809-48a4-9097-05460b06f1b4 | 1 | 2019-09-13T17:11:00 | 2 | Previous entry by CreatedAt in this ID group reached Value 3 |
6c5fbe89-ce79-4394-8c11-3efb7d924efb | 1 | 2019-09-13T17:12:00 | 3 | First in ID group |
6c5fbe89-ce79-4394-8c11-3efb7d924efb | 2 | 2019-09-13T17:13:00 | 3 | None |
02d97338-ea82-4a1e-a1be-638a120c08e5 | 1 | 2019-09-13T17:14:00 | 4 | First in ID group |
Last active
September 13, 2019 17:51
-
-
Save Suchiman/423e6f91641586a04044ce596d2dc060 to your computer and use it in GitHub Desktop.
ID | Value | CreatedAt | ID | GroupNumber |
---|---|---|---|---|
036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 | 2019-09-13 17:08:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 | 2019-09-13 17:08:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 2 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 | 2019-09-13 17:08:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 | 2019-09-13 17:08:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 2 | 2019-09-13 17:09:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 2 | 2019-09-13 17:09:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 2 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 2 | 2019-09-13 17:09:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 2 | 2019-09-13 17:09:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 3 | 2019-09-13 17:10:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 3 | 2019-09-13 17:10:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 2 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 3 | 2019-09-13 17:10:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 3 | 2019-09-13 17:10:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 | 2019-09-13 17:11:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 | 2019-09-13 17:11:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 2 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 | 2019-09-13 17:11:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 | 2019-09-13 17:11:00.0000000 | 036A2E7D-B809-48A4-9097-05460B06F1B4 | 1 |
6C5FBE89-CE79-4394-8C11-3EFB7D924EFB | 1 | 2019-09-13 17:12:00.0000000 | 6C5FBE89-CE79-4394-8C11-3EFB7D924EFB | 3 |
6C5FBE89-CE79-4394-8C11-3EFB7D924EFB | 1 | 2019-09-13 17:12:00.0000000 | 6C5FBE89-CE79-4394-8C11-3EFB7D924EFB | 2 |
6C5FBE89-CE79-4394-8C11-3EFB7D924EFB | 2 | 2019-09-13 17:13:00.0000000 | 6C5FBE89-CE79-4394-8C11-3EFB7D924EFB | 3 |
6C5FBE89-CE79-4394-8C11-3EFB7D924EFB | 2 | 2019-09-13 17:13:00.0000000 | 6C5FBE89-CE79-4394-8C11-3EFB7D924EFB | 2 |
02D97338-EA82-4A1E-A1BE-638A120C08E5 | 1 | 2019-09-13 17:14:00.0000000 | 02D97338-EA82-4A1E-A1BE-638A120C08E5 | 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS List | |
CREATE TABLE [dbo].[List] | |
( | |
[ID] [uniqueidentifier] NOT NULL, | |
[Value] [int] NOT NULL, | |
[CreatedAt] [datetime2](7) NOT NULL | |
) | |
GO | |
INSERT [dbo].[List] ([ID], [Value], [CreatedAt]) VALUES (N'036a2e7d-b809-48a4-9097-05460b06f1b4', 1, CAST(N'2019-09-13T17:08:00' AS DateTime2)) | |
INSERT [dbo].[List] ([ID], [Value], [CreatedAt]) VALUES (N'036a2e7d-b809-48a4-9097-05460b06f1b4', 2, CAST(N'2019-09-13T17:09:00' AS DateTime2)) | |
INSERT [dbo].[List] ([ID], [Value], [CreatedAt]) VALUES (N'036a2e7d-b809-48a4-9097-05460b06f1b4', 3, CAST(N'2019-09-13T17:10:00' AS DateTime2)) | |
INSERT [dbo].[List] ([ID], [Value], [CreatedAt]) VALUES (N'036a2e7d-b809-48a4-9097-05460b06f1b4', 1, CAST(N'2019-09-13T17:11:00' AS DateTime2)) | |
INSERT [dbo].[List] ([ID], [Value], [CreatedAt]) VALUES (N'6c5fbe89-ce79-4394-8c11-3efb7d924efb', 1, CAST(N'2019-09-13T17:12:00' AS DateTime2)) | |
INSERT [dbo].[List] ([ID], [Value], [CreatedAt]) VALUES (N'6c5fbe89-ce79-4394-8c11-3efb7d924efb', 2, CAST(N'2019-09-13T17:13:00' AS DateTime2)) | |
INSERT [dbo].[List] ([ID], [Value], [CreatedAt]) VALUES (N'02d97338-ea82-4a1e-a1be-638a120c08e5', 1, CAST(N'2019-09-13T17:14:00' AS DateTime2)) | |
GO | |
-- Query | |
WITH [Group] (ID, GroupNumber) | |
AS | |
( | |
SELECT [List].[ID], ROW_NUMBER() OVER (PARTITION BY [List].[Value] ORDER BY [List].[CreatedAt]) AS GroupNumber | |
FROM [List] | |
) | |
SELECT [List].*, [Group]. * | |
FROM [List] | |
LEFT JOIN [Group] | |
ON [Group].[ID] = [List].[ID] | |
ORDER BY [List].[CreatedAt] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment