i complete beginner in mysql , wanted me. want dtr user interface
there time in , time out. have fields -id_biometrics,empno,datecreated,time_created,status,device
problem if employee forgot time in or time out, want put time in or time out "null" here coded.
select start_log.empno "employee number", start_log.date_created, start_log.time_created "time in", end_log.time_created "time out" biometrics start_log inner join biometrics end_log on start_log.empno = end_log.empno start_log.status =0 , end_log.status =1 , start_log.empno =2 group start_log.date_created, start_log.empno
and output here if completes time in , time out day is.
employee number|date_created |time_in | time_out 2 | 2013-07-15 | 11:08:07 | 15:00:00
and if he/she forgots time out or time in shows mysql returned empty result set (i.e. 0 rows). ( query took 0.0016 sec )
what wanted is
employee number | date_created |time_in | time_out 3 | 2013-07-15 | 11:50:00 | null
please me this. needed badly thanks.
are looking this?
select empno, date_created, min(case when status = 0 time_created end) time_in, min(case when status = 1 time_created end) time_out biometrics group empno, date_created
sample output:
+-------+--------------+----------+----------+ | empno | date_created | time_in | time_out | +-------+--------------+----------+----------+ | 2 | 2013-07-15 | 11:08:07 | 15:00:00 | | 3 | 2013-07-15 | 11:50:00 | null | | 4 | 2013-07-15 | null | 16:00:00 | +-------+--------------+----------+----------+
here sqlfiddle demo
update if may have multiple in or out records , want fetch first in , last out use max()
aggregate time_out
select empno, date_created, min(case when status = 0 time_created end) time_in, max(case when status = 1 time_created end) time_out biometrics group empno, date_created
here sqlfiddle demo
Comments
Post a Comment