获得最佳方法(第一次进入)& (上次出)每个员工每天的出勤记录 [英] Best approach to get (first time in) & (last time out) for each employees attendance record on each day

查看:61
本文介绍了获得最佳方法(第一次进入)& (上次出)每个员工每天的出勤记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,



我很困惑,这是获得员工(第一次参加)的最佳方法。 (最后一次)他们每天登录我们的生物识别时钟系统。



例如,如果Jorge的日程安排在3月9日上午8点到下午5点, 2013年

他多次登录,并且出席记录的时间为:10:05,10:10,10:15,时间为5:00。 5:30,5:45



系统今天只能获得Jorge的出席率:



时间:2013年3月9日 - 上午10:05&超时时间:2013年3月9日 - 下午05:45



Emp_name Emp_time Emp_type

Jorge 3/9 / 2013 10:00在

Jorge 3/9/2013 10:10在

Jorge 3/9/2013 17:00 Out

Jorge 3/9/2013 17:30 Out

Mike 3/9/2013 17:40 Out

Jorge 3/9/2013 10:02在

Jorge 3/9/2013 17:00 Out

Jorge 2013/9/13 17:00 Out

Jorge 3/9/2013 17:00 Out

Jorge 3/9/2013 10:14在

Mike 3/9/2013 10:00在

Mike 3/9/2013 10:10在

Jorge 3/9/2013 17:00 Out

Mike 3/9/2013 17:30 Out

Jorge 3 / 9/2013 17:40 Out

Mike 3/9/2013 10:02在

Mike 3/9/2013 17:00 Out

Mike 3/9/2013 17:00 Out

Mike 3/9/2013 17:00 Out

Jorge 3/9/2013 10:14在





表nam e:Raw_Record

Col1 = Emp_name

Col2 = Emp_time

Col3 = Emp_type



老实说,我还没有尝试任何代码,因为我仍然在想什么是最好的方法(第一次进入)& (最后一次)每天每位员工的出勤记录。



任何人的想法都会非常有用。提前谢谢。

解决方案

Microsoft SQL Server示例:

 选择  distinct  
CE.Emp_Name,
select min(Emp_Time)来自 Raw_Record 作为 MINCE 其中 MINCE.Emp_Type = ' 在' MINCE.Emp_Name = CE.Emp_Name AND CONVERT varchar 8 ),MINCE.EMP_TIME, 112 )= CONVERT( varchar 8 ),CE.Emp_Time, 112 )) 作为 MinTime,
选择 max(Emp_Time)来自 Raw_Record 作为 MAXCE 其中 MAXCE.Emp_Type = ' Out' MAXCE.Emp_Name = CE.Emp_name AND CONVERT varchar 8 ),MAXCE.EMP_TIME, 112 )= CONVERT( varchar 8 ),CE.Emp_Time, 112 ))作为 MaxTime
来自 Raw_Record 作为 CE





MINCE (最小ClockEvents)是用于选择最短时间的Raw_Record表的table_alias。

MAXCE (最大ClockEvents)是制表符用于选择最大时间的Raw_Record表的le_alias。

CE (ClockEvents)是主SELECT语句中使用的Raw_Record表的table_alias。


Good Day,

I am so confused which is the best approach to get employee's (first time in) & (last time out) each day when they have login to our biometrics clock system.

For instance if "Jorge" has a schedule of 8am - 5pm on March 9, 2013
and he logged many times and has a record attendance of: time in at 10:05, 10:10, 10:15 and Time out at : 5:00. 5:30, 5:45

System should only gets "Jorge's" attendance for today like:

Time in: March 9, 2013 - 10:05 am & Time out: March 9, 2013 - 05:45 pm

Emp_name Emp_time Emp_type
Jorge 3/9/2013 10:00 In
Jorge 3/9/2013 10:10 In
Jorge 3/9/2013 17:00 Out
Jorge 3/9/2013 17:30 Out
Mike 3/9/2013 17:40 Out
Jorge 3/9/2013 10:02 In
Jorge 3/9/2013 17:00 Out
Jorge 3/9/2013 17:00 Out
Jorge 3/9/2013 17:00 Out
Jorge 3/9/2013 10:14 In
Mike 3/9/2013 10:00 In
Mike 3/9/2013 10:10 In
Jorge 3/9/2013 17:00 Out
Mike 3/9/2013 17:30 Out
Jorge 3/9/2013 17:40 Out
Mike 3/9/2013 10:02 In
Mike 3/9/2013 17:00 Out
Mike 3/9/2013 17:00 Out
Mike 3/9/2013 17:00 Out
Jorge 3/9/2013 10:14 In


table name: Raw_Record
Col1 = Emp_name
Col2 = Emp_time
Col3 = Emp_type

Honestly i haven't tried any code because i am still thinking what is the best approach to get (first time in) & (last time out) for each employees attendance record on each day.

An idea from anyone would be very much helpful. thanks in advance.

解决方案

Example for Microsoft SQL Server:

select distinct
CE.Emp_Name,
(select min(Emp_Time) from Raw_Record As MINCE where MINCE.Emp_Type ='In' and MINCE.Emp_Name=CE.Emp_Name AND CONVERT(varchar(8),MINCE.EMP_TIME,112)=CONVERT(varchar(8),CE.Emp_Time,112)) As MinTime,
(select max(Emp_Time) from Raw_Record As MAXCE where MAXCE.Emp_Type ='Out' and MAXCE.Emp_Name=CE.Emp_name AND CONVERT(varchar(8),MAXCE.EMP_TIME,112)=CONVERT(varchar(8),CE.Emp_Time,112)) As MaxTime
from Raw_Record As CE



MINCE (Minimum ClockEvents) is table_alias for Raw_Record table used in selection of Minimum Time.
MAXCE (Maximum ClockEvents) is table_alias for Raw_Record table used in selection of Maximum Time.
CE (ClockEvents) is table_alias for Raw_Record table used in main SELECT statement.


这篇关于获得最佳方法(第一次进入)& (上次出)每个员工每天的出勤记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆