2013-01-25, 13:54
#1
Har en knepig fråga som jag har försökt lösa men inte lyckats. Har med exempel tabell nedan med data:
Det är just att det kan finnas flera grupper med StatusID 4 i varje ResourceID som jag går bet på.
Det jag vill ha ut är alltså den första TimeUpdate tiden för den sista streamen för varje ResourceID.
mao: (ResourceID TimeUpdate)
1 2013-01-25 12:38:38.847
2 2013-01-25 12:40:37.150
Någon som har några lösningar eller ideér?
Kod:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Loggen]( [EventID] [int] IDENTITY(1,1) NOT NULL, [ResourceID] [int] NOT NULL, [Comment] [nvarchar](50) NULL, [StatusID] [int] NOT NULL, [TimeUpdate] [datetime] NOT NULL, CONSTRAINT [PK_Loggen] PRIMARY KEY CLUSTERED ( [EventID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET IDENTITY_INSERT [dbo].[Loggen] ON INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (1, 1, N'Testevent', 1, CAST(0x0000A15100CEC85B AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (2, 1, N'Skapar koppling', 2, CAST(0x0000A15100CF7B3A AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (5, 1, N'Koppling väntar', 3, CAST(0x0000A15100CFD5C8 AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (6, 1, N'Koppling streamar', 4, CAST(0x0000A15100CFF7F4 AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (7, 1, N'Koppling streamar', 4, CAST(0x0000A15100D0045E AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (10, 1, N'Koppling väntar', 3, CAST(0x0000A15100D01616 AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (12, 1, N'Koppling streamar', 4, CAST(0x0000A15100D02A68 AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (14, 1, N'Koppling streamar', 4, CAST(0x0000A15100D0447B AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (15, 1, N'Koppling väntar', 3, CAST(0x0000A15100D0525E AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (16, 1, N'Koppling streamar', 4, CAST(0x0000A15100D05E66 AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (17, 1, N'Koppling streamar', 4, CAST(0x0000A15100D06CAA AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (18, 1, N'Koppling avslutad', 5, CAST(0x0000A15100D07B0B AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (19, 2, N'Återlistning', 1, CAST(0x0000A15100D0AF1C AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (20, 2, N'Skapar koppling', 2, CAST(0x0000A15100D0BBDC AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (21, 2, N'Koppling streamar', 4, CAST(0x0000A15100D0CBE9 AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (22, 2, N'Koppling väntar', 3, CAST(0x0000A15100D0DF1B AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (23, 2, N'Koppling streamar', 4, CAST(0x0000A15100D0E909 AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (25, 2, N'Koppling streamar', 4, CAST(0x0000A15100D0FF7E AS DateTime)) INSERT [dbo].[Loggen] ([EventID], [ResourceID], [Comment], [StatusID], [TimeUpdate]) VALUES (26, 2, N'Koppling avslutad', 5, CAST(0x0000A15100D12A8A AS DateTime)) SET IDENTITY_INSERT [dbo].[Loggen] OFF ALTER TABLE [dbo].[Loggen] ADD CONSTRAINT [DF_Loggen_TimeUpdate] DEFAULT (getutcdate()) FOR [TimeUpdate] GO
Det är just att det kan finnas flera grupper med StatusID 4 i varje ResourceID som jag går bet på.
Det jag vill ha ut är alltså den första TimeUpdate tiden för den sista streamen för varje ResourceID.
mao: (ResourceID TimeUpdate)
1 2013-01-25 12:38:38.847
2 2013-01-25 12:40:37.150
Någon som har några lösningar eller ideér?