Click to See Complete Forum and Search --> : How to get last timeIN/Out ?
ocpdude
07-18-2002, 12:55 PM
if I have this
empid--timeIn----------------------timeOut
1-------18-JUL-02 08:55:48---18-JUL-02 08:56:33
1-------18-JUL-02 10:49:00---18-JUL-02 12:49:00
1-------18-JUL-02 01:49:00------null
how can I get the last timeIn and the last timOut ?
Thanks
stecal
07-18-2002, 01:20 PM
select max of each.
ocpdude
07-18-2002, 02:10 PM
Hi,
select max doesn't solve the problem.. let me try to explain
it further.
the idea is the employee will be clocking In and out during the
day and I am trying to find when he last clocked In and if he clocked out.
In my previous example.. the emp is still clocked so if I use max I'll get 18-JUL-02 01:49:00 for timeIn and
18-JUL-02 12:49:00 for timeOut wich is not true. because he
is not clocked out yet.
I hope this helps
jmodic
07-18-2002, 03:46 PM
How about adding simple WHERE condition?
... WHERE timeOut IS NOT NULL;
stecal
07-18-2002, 03:47 PM
That shows when clocked out, but not for someone who is still clocked in.
marist89
07-18-2002, 04:09 PM
... WHERE timeOut IS NULL;
ocpdude
07-18-2002, 04:18 PM
in the case when
timeout is null (both max(timeIn) and max(timeout)=null
timeout is not null (just like STECAL said)
marist89
07-18-2002, 04:22 PM
or, maybe you're looking for something like:
SQL> select * from xyz;
EMPNO CLOCK_IN CLOCK_OUT
---------- ------------------- -------------------
1 07/17/2002 15:09:17 07/17/2002 23:09:17
1 07/17/2002 15:09:19 07/17/2002 23:09:19
1 07/17/2002 15:09:26 07/17/2002 23:09:26
1 07/17/2002 15:09:39
2 07/17/2002 15:09:52 07/17/2002 23:09:52
2 07/17/2002 15:10:53
3 07/17/2002 15:20:59 07/17/2002 23:20:59
7 rows selected.
SQL> select e.empno, e.clock_in, e.clock_out
2 from xyz e, (select empno, max(clock_in) clock_in from xyz group by empno) a
3 where a.empno = e.empno
4 and a.clock_in = e.clock_in
5 /
EMPNO CLOCK_IN CLOCK_OUT
---------- ------------------- -------------------
1 07/17/2002 15:09:39
2 07/17/2002 15:10:53
3 07/17/2002 15:20:59 07/17/2002 23:20:59
ocpdude
07-18-2002, 04:31 PM
Thank you