我有以下查询,该查询返回日期范围内的时钟输入, 我需要查询以在新字段中返回日期中每个时钟的最小和最大时钟,然后我将能够计算出工作时间。
任何帮助将不胜感激
谢谢
Select staffid, staffname, clockdate, clocktime
from database
where ClockDate >='2019-01-01'
答案 0 :(得分:1)
如果您希望每行每天每位员工的最短和最长时间,请使用窗口功能:
Select staffid, staffname, clockdate, clocktime,
min(clocktime) over (partition by staffid, clockdate) as earliest_time,
max(clocktime) over (partition by staffid, clockdate) as latest_time
from database
where ClockDate >= '2019-01-01';