我有下表
CREATE TABLE [dbo].[DeviceLogs](
[DeviceLogId] [int] IDENTITY(1,1) NOT NULL,
[UserId] [nvarchar](50) NULL,
[LogDate] [datetime2](0) NULL,
)
GO
数据样本
1 1 2013-05-29 11:05:15 //accepted (its the first occurance for userid 1)
2 1 2013-05-29 11:05:20 //discarded (within 5 mins from 1st record)
3 1 2013-05-29 11:07:56 //discarded (within 5 mins from 1st record)
4 1 2013-05-29 11:11:15 //accepted (after 5 mins from 1st occurance)
5 2 2013-05-29 11:06:05 //accepted (its the first occurance for userid 2)
6 2 2013-05-29 11:07:18 //discarded (within 5 mins from 1st record)
7 2 2013-05-29 11:09:38 //discarded (within 5 mins from 1st record)
8 2 2013-05-29 11:12:15 //accepted (after 5 mins from 1st occurance)
我只想选择从先前选择的记录开始 5 分钟后发生的记录,包括数据集中的第一条记录
所需的输出是
1 1 2013-05-29 11:05:15
4 1 2013-05-29 11:11:15
5 2 2013-05-29 11:06:05
8 2 2013-05-29 11:12:15
我正在尝试 GroupBy 但没有给出日期
db.DeviceLogs.GroupBy(g=>new {g.LogDate.Year,
g.LogDate.Month,
g.LogDate.Day,
g.LogDate.Hour,
g.LogDate.Minutes,
g.UserID})
.Select(s=>new {UserID=s.Key.UserID, s.???});
先感谢您。