我想获得标题状态,列出选定日期范围内每天所有用户的第一次和最后一次刷卡时间的列表(可由用户选择)。现在,每次用户滑动时我都会返回。
Mike Donati 2019-05-29 09:21:01.673 2019-05-29 09:21:01.673
Mike Donati 2019-05-29 09:21:10.207 2019-05-29 09:21:10.207
Mike Donati 2019-05-29 09:23:21.737 2019-05-29 09:23:21.737
Mike Donati 2019-05-29 09:23:30.430 2019-05-29 09:23:30.430
Mike Donati 2019-05-29 09:33:17.640 2019-05-29 09:33:17.640
Mike Donati 2019-05-29 09:33:21.587 2019-05-29 09:33:21.587
Mike Donati 2019-05-29 09:36:16.687 2019-05-29 09:36:16.687
Mike Donati 2019-05-29 09:36:25.083 2019-05-29 09:36:25.083
Mike Donati 2019-05-29 10:00:30.820 2019-05-29 10:00:30.820
Mike Donati 2019-05-29 10:01:07.313 2019-05-29 10:01:07.313
Mike Donati 2019-05-29 10:42:13.057 2019-05-29 10:42:13.057
Mike Donati 2019-05-29 10:42:15.410 2019-05-29 10:42:15.410
Mike Donati 2019-05-29 16:16:51.493 2019-05-29 16:16:51.493
Mike Donati 2019-05-29 16:16:57.637 2019-05-29 16:16:57.637
Mike Donati 2019-05-30 07:49:33.710 2019-05-30 07:49:33.710
Mike Donati 2019-05-30 07:51:56.003 2019-05-30 07:51:56.003
Mike Donati 2019-05-30 08:24:29.797 2019-05-30 08:24:29.797
Mike Donati 2019-05-30 08:24:38.743 2019-05-30 08:24:38.743
SELECT
u.[FirstName] + ' ' + u.[LastName] AS EmployeeName
,min(e.LoggedTime) OVER(PARTITION BY e.LoggedTime) as first
,max(e.LoggedTime) OVER(PARTITION BY e.LoggedTime) as last
FROM [ProtegeGX].[dbo].[Users] AS u
LEFT JOIN [ProtegeGXEvents].[dbo].[Events] AS e ON e.RecordIndex1=u.UserID
LEFT JOIN [ProtegeGX].[dbo].[EventTypes] AS et on e.EventTypeID = et.EventTypeID
WHERE e.LoggedTime Between '2019-05-29'and '2019-05-31' and u.userid = 97
GROUP BY
u.[FirstName] + ' ' + u.[LastName]
,(e.LoggedTime)
ORDER BY
u.[FirstName] + ' ' + u.[LastName]
我想要每位用户每天的初始滑动时间和最后一次滑动时间
user first swipe last swipe
Mike Donati 2019-05-29 09:21:01.673 2019-05-29 16:16:57.637
Mike Donati 2019-05-30 07:49:33.710 2019-05-30 08:24:38.743
答案 0 :(得分:0)
当您似乎想要简单的聚合时,为什么要使用窗口函数?
<wj-flex-grid-column *ngFor="let col of columnDefinitions"
[minWidth]="200" width="*"
[header]="col.header" [binding]="col.binding" [visible]="col.visible"
[allowDragging]="false" [wordWrap]="true" >
</wj-flex-grid-column>
我将SELECT u.[FirstName] + ' ' + u.[LastName] AS EmployeeName
min(e.LoggedTime) as first
max(e.LoggedTime) as last
FROM [ProtegeGX].[dbo].[Users] u JOIN
[ProtegeGXEvents].[dbo].[Events] e
ON e.RecordIndex1 = u.UserID JOIN
[ProtegeGX].[dbo].[EventTypes] et
on e.EventTypeID = et.EventTypeID
WHERE e.LoggedTime Between '2019-05-29' AND '2019-05-31' AND
u.userid = 97
GROUP BY u.[FirstName] + ' ' + u.[LastName];
更改为内部联接,因为JOIN
子句仍然限制了它们。
如果您想每天 这样做,
WHERE