![](/img/trans.png)
[英]MySQL - Getting All Employees First Punch in time and Last Punch in time within Date Range
[英]how to select the first punch of an associate
如果你只想要一行,那么使用top (1)
:
select top (1) ts.*
from VP_TIMESHEETITMV42 ts
where ts.eventdate = '2019-12-18' and
ts.EMPLOYEEID = 283401
order by ts.stardtm;
我假設employeeid
是一個數字。 如果是這樣,則不應將單引號用於比較值。
如果您希望每天一行並且員工第一次打卡,您可以使用相關子查詢進行過濾:
select t.*
from VP_TIMESHEETITMV42 t
where t.startdtm = (
select min(t1.startdtm)
from VP_TIMESHEETITMV42 t1
where t1.eventdate = t.eventdate and t1.employee_id = t.employee_id
)
然后,您可以在where
子句中添加更多條件以過濾特定員工和/或特定日期。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.