Find the time of reporting of employees

Hello

I followed two tables

PERMITTEDABSCENCE

EMPID

DATE

LEAVEFROM

LEAVETO

TYPE

1

01/01/2014

08:00

12:00

CL

1

01/01/2014

12:00

13:00

DUTY

2

01/01/2014

09:00

16:30

CL

3

01/02/2014

12:00

16:30

CL

EMPLOYEESHIFTS

EMPID

DATE

SHIFTSTART

1

01/01/2014

08:00

2

01/01/2014

09:00

3

01/02/2014

09:00

I want to know the time during which the employee must declare for each day.

This is necessary when calculating the minutes of delay for employees.

Normally an employee must get customs SHIFT START TIME that is stored in the EMPLOYEESHIFTS table.

But if an employee is allowed to be described (leave/duty etc.), he had to report for duty after this period [only if authorized period start time is exactly to the SHIFT start time] and its end minutes will be counted from the moment here.

Here, a complication is that there may be consecutive leave and then the start time of the work duty must be discovered as a result.

for example.

01/01/2014, an employee is on leave from 08:00 to 12:00 so it is assumed that he had to report for duty at 12:00.

But as it is in service from 12:00 to 15:00, he had to report for duty at 13:00

POWER REQUIRED

EMPID

DATE

WORKSTARTTIME

1

01/01/14

13:00

2

01/01/14

16:30

3

01/02/14

09:00

Is this possible?

I use oracle 10g.

Examples of data

create the table employeeshifts as

(

Select 1 empid, to_date('01/01/2014','DD/MM/YYYY') stand,' 08:00 ' shiftstart of all the double union

Select 2 empid, to_date('01/01/2014','DD/MM/YYYY') stand,' 09:00 ' shiftstart of all the double union

Select 3 empid, to_date('02/01/2014','DD/MM/YYYY') stand,' 09:00 ' shiftstart of the double

);

create the table authorisedabsence as

(select 1 employee_id, to_date (1 January 2014 ', ' dd/mm/yyyy') subsist, to_date (08 January 1 2014:00 ',' dd/mm/yyyy hh24 ') frmdt, to_date (12 January 1 2014:00 ',' dd/mm/yyyy hh24 ') todt, "CL" type of Union double all the)

Select 1 employee_id, to_date (1 January 2014 ', ' dd/mm/yyyy') subsist, to_date (12 January 1 2014:00 ',' dd/mm/yyyy hh24 ') frmdt, to_date (16 January 1 2014:00 ',' dd/mm/yyyy hh24 ') todt, "CL" type of Union double all the

Select employee_id 2, to_date (January 1, 2014 ', ' dd/mm/yyyy') subsist, to_date (09 January 1 2014:00 ',' dd/mm/yyyy hh24 ') frmdt, to_date (16 January 1 2014:30 ',' dd/mm/yyyy hh24 ') todt, "CL" type of Union double all the

Select 3 employee_id, to_date (1 January 2014 ', ' dd/mm/yyyy') subsist, to_date (January 1, 2014 12:00 ',' dd/mm/yyyy hh24 ') frmdt, to_date (16 January 1 2014:30 ',' dd/mm/yyyy hh24 ') todt, "CL" type double

);

Hello

2730134 wrote:

Hello

I followed two tables

PERMITTEDABSCENCE

EMPID

DATE

LEAVEFROM

LEAVETO

TYPE

1

01/01/2014

08:00

12:00

CL

1

01/01/2014

12:00

13:00

DUTY

2

01/01/2014

09:00

16:30

CL

3

01/02/2014

12:00

16:30

CL

EMPLOYEESHIFTS

EMPID

DATE

SHIFTSTART

1

01/01/2014

08:00

2

01/01/2014

09:00

3

01/02/2014

09:00

I want to know the time during which the employee must declare for each day.

This is necessary when calculating the minutes of delay for employees.

Normally an employee must get customs SHIFT START TIME that is stored in the EMPLOYEESHIFTS table.

But if an employee is allowed to be described (leave/duty etc.), he had to report for duty after this period [only if authorized period start time is exactly to the SHIFT start time] and its end minutes will be counted from the moment here.

Here, a complication is that there may be consecutive leave and then the start time of the work duty must be discovered as a result.

for example.

01/01/2014, an employee is on leave from 08:00 to 12:00 so it is assumed that he had to report for duty at 12:00.

But as it is in service from 12:00 to 15:00, he had to report for duty at 13:00

POWER REQUIRED

EMPID

DATE

WORKSTARTTIME

1

01/01/14

13:00

2

01/01/14

16:30

3

01/02/14

09:00

Is this possible?

I use oracle 10g.

Examples of data

create the table employeeshifts as

(

Select 1 empid, to_date('01/01/2014','DD/MM/YYYY') stand,' 08:00 ' shiftstart of all the double union

Select 2 empid, to_date('01/01/2014','DD/MM/YYYY') stand,' 09:00 ' shiftstart of all the double union

Select 3 empid, to_date('02/01/2014','DD/MM/YYYY') stand,' 09:00 ' shiftstart of the double

);

create the table authorisedabsence as

(select 1 employee_id, to_date (1 January 2014 ', ' dd/mm/yyyy') subsist, to_date (08 January 1 2014:00 ',' dd/mm/yyyy hh24 ') frmdt, to_date (12 January 1 2014:00 ',' dd/mm/yyyy hh24 ') todt, "CL" type of Union double all the)

Select 1 employee_id, to_date (1 January 2014 ', ' dd/mm/yyyy') subsist, to_date (12 January 1 2014:00 ',' dd/mm/yyyy hh24 ') frmdt, to_date (16 January 1 2014:00 ',' dd/mm/yyyy hh24 ') todt, "CL" type of Union double all the

Select employee_id 2, to_date (January 1, 2014 ', ' dd/mm/yyyy') subsist, to_date (09 January 1 2014:00 ',' dd/mm/yyyy hh24 ') frmdt, to_date (16 January 1 2014:30 ',' dd/mm/yyyy hh24 ') todt, "CL" type of Union double all the

Select 3 employee_id, to_date (1 January 2014 ', ' dd/mm/yyyy') subsist, to_date (January 1, 2014 12:00 ',' dd/mm/yyyy hh24 ') frmdt, to_date (16 January 1 2014:30 ',' dd/mm/yyyy hh24 ') todt, "CL" type double

);

Workstartime is the end of the period of absence authroised (if it exists), or shiftstart.  This looks like a job for NVL.

How do you know if there is a period of leave of absence?  There will be a shiftstart if is between the beginning of the period and the end of the period.  As you pointed out, however, it's tricky because a period of absence can be any number of consecutive lines in the authorisedabsence table.  It would be so much easier if there was only 1 row per employee per day, so let's create a set of results (combined_absence) that is the beginning and the end of the time for consecutive periods.

How can we detect consecutive periods?  We can use the technique of fixed difference, it's what got_grp_id does.

WITH got_grp_id AS

(

SELECT employee_id, subsist, frmdt, todt

, todt - SUM (todt - frmdt) OVER (PARTITION BY employee_id, subsist

ORDER BY frmdt

) AS grp_id

Of authorisedabsence

)

combined_absence AS

(

SELECT employe_id, subsist

MIN (frmdt) AS grp_frmdt

MAX (todt) AS grp_todt

OF got_grp_id

GROUP BY employee_id, survive, grp_id

)

improved_employeeshifts AS

(

SELECT empid

subsist

, subsist + (TO_DATE (shiftstart, "HH24")

-TO_DATE (' 00:00 ', "HH24")

) AS shiftstartdate

Of employeeshifts

)

SELECT es.empid

es.thedate

NVL (ca.grp_todt, es.shiftstartdate) AS workstarttime

Of improved_employeeshifts are

LEFT OUTER JOIN combined_absence ON es.empid = ca.employee_id ca

AND es.shiftstartdate BETWEEN ca.grp_frmdt

AND ca.grp_todt

ORDER BY es.empid

es.thedate

;

The results I get from your sample data are not exactly what you posted:

EMPID CONTINUE WORKSTARTTIME

---------- ---------------- ----------------

1 01/01/2014 00:00 01/01/2014 16:00

2 01/01/2014 00:00 01/01/2014 16:30

3 01/02/2014 00:00 01/02/2014 09:00

Time 13:00 do not exist anywhere in the sample data, so I think that you don't really want for the empid workstarttime = 1.

Information on the dates and times (for example, shiftstart) belongs to DATE columns, not VARCHAR2s.  If you store information in the wrong data type, you will need to convert the right data type in any statement that has to manipulate it in any way.  This makes the subquery improved_employeeshifts above.  You are wasting time and risking execution errors, by the conversion of a VARCHAR2 to a DATE in queries like this.  If would be much more effective, more robust and simpler if you have stored to a DATE just shiftstart all along.

I guess that this period of an absence never begins or ends in the middle of one (for the same employee).  In other words, if a period is from 08:00 to 12:00, then you will never have another one that starts at 11:30 the same day.  If my assumption is wrong, and you can have overlapping of absences like that, then you can combine still, but it's more complicated than what I used above.

For an explanation of the technique fixed Difference in combined_absence, see

Analytic Question lag and lead and/or

Re: Ranking of queries

Tags: Database

Similar Questions

  • Could not find the Time Capsule for Time Machine backup drive

    My iMac is running El Capitan and Time Machine is unable to find the Time Capsule backup drive.  I blew the backup several times in hopes that it will fix the problem.   The only thing I found which will allow a return to the top is to unplug the Time Capsule and plug it in again.  The work around works only once, then it's back to "can't find the backup disk.

    For anyone a cela or similar questions are you go in your Utilities folder (in your applications folder) and run the utility airport to see what he says about the disks attached. This cannot work for the readers of time capsule Apple rather than third party readers who have been designated as the backup time drives machine.

  • How to find the time to what zero crossing point occur using zero crossing vi

    Hello 
    Im trying to find the time to the point of inflection of a Bio-Signal with the 2nd derivative, then detecet the point of zero of the derivative signal
    What I need, is to mark the point of inflection on my Bio-Signal at the point where the derivative signal crosses the zero.

    The second has two scales on the graph, one on each side.  The first has only a single scale. I do not change the name of VI, so both have the same name.

    Lynn

  • Find the time to restore a data file

    RDBMS version: 11.2.0.4

    Platform: Oracle Linux 6.4

    To test our backup RMAN Tape (Netbackup), we have created a table called BACKUPTEST with a single space data file.

    Then, we have removed the data file. Then was restored and recovered with RMAN's data file and tablespace was again online.

    I wanted to show the evidence to my manager that the data file has been restored. But v$ datafile. CREATION_TIME will show the time when the tablespace is imagined. Is there another way, I could find the time when the data file has been restored other than log RMAN.

    Below is an excerpt after the data file has been restored.

    $ sqlplus / as sysdba

    SQL * more: Production of the version 11.2.0.4.0 Fri dec 19 15:08:03 2013

    Copyright (c) 1982, 2013, Oracle.  All rights reserved.

    Connected to:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production

    With partitioning, Real Application Clusters, Automatic Storage Management, OLAP,.

    Options of Data Mining and Real Application Testing

    SQL > select TABLESPACE_NAME, status of dba_tablespaces where nom_tablespace = 'BACKUPTEST ';

    STATUS TABLESPACE_NAME

    ------------------------------ ---------

    BACKUPTEST ONLINE

    SQL > alter session set nls_date_format = "DD-MM-YYYY HH24."

    Modified session.

    SQL > select CREATION_TIME of v$ datafile where FILE # = 78;

    CREATION_TIME

    ----------------

    19/12/2013-12:16

    SQL > select CREATION_TIME, last_time v$ datafile where FILE # = 78;

    CREATION_TIME LAST_TIME

    ---------------- ----------------

    19/12/2013-12:16

    SQL >

    19/12/2013 12:16 is the hour when the tablespace has been created with this data file no time, it has been restored from a backup RMAN.

    Check the alert.log.  There will be messages about the RESTORATION and RECOVERY actions.

    Hemant K Collette

  • How to find the path of reports to PDF and send them via JAVA?

    Hi expert,

    We have created many reports of OBIEE, how to find the way of reports to PDF and send them via JAVA?
    Catalog/shared /..., but it is a binary file that is not sent to the customers.

    Hey kobe,.

    You can try this:

    http://satyaobieesolutions.blogspot.com/2012/07/setting-up-iBOT-to-save-report-to.html

  • How to find the time to process a request?

    IM using oracle express edition, can someone help me, how to find the time to process a request?

    Trace queries and tkprof the trace file generated.
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e16638/SQLTrace.htm#PFGRF01010

  • Find the time displaced table

    Hi all

    I'm in oracle 10 g 2. I have a table being stripped of some process. We have several tasks scheduled for every night.

    Is it possible to find the time of what a table is dropped, just to make a guess what regular process could be the culprit?

    Enjoy your suggessions

    Thanks in advance

    NU
    select object_name,original_name,droptime
    from recyclebin
    

    If recyclebin is enabled
    So you can be insterested to configure auditing

    Best regards

    Maxim

  • Safari crashes all the time without report. Now, nothing happens

    Dear people,

    I'm on 10.11.2. Latest version of the software. MacBook Pro mid-late 2009. Until today, everything worked like a charm.

    And then Safari crashed all of a sudden all the time when I tried to open another tab (~ 5 have been opened)

    That's what I did:

    -J' all caches emptied

    -delete all cookies

    -remove all history

    -J' disabled all extensions

    -J' deleted Cache.db

    -J' tried Safari in another account - same problems

    -J' deleted all preferences

    -J' reinstalled Mac OS X

    No luck.

    And I get an error report or whatever it is. It keeps crashing.

    I need help please!

    Hey! Take a look at this. This temporary has helped a number of users here. Over time, everything should be resolved then wait for a while.

    A possible solution to the problem of address bar: disable the Safari Suggestions

    If you have problems to open Web pages, take a look at these techniques proposed by Apple of troubleshooting.

    https://support.Apple.com/en-us/HT204098

    Go to the Safari menu (at the top right of your screen next to the Apple icon), choose 'Quit Safari'

    Press the "Shift" key and while holding this button on your unique keyboard, click the icon of Safari on your Dock.

    Open Safari - Preferences - Privacy - data to remove any Web site.

    Open the menu to go with the Option (Alt) key - library - key locate Safari folder and place it on your desktop. Restart your Mac, open Safari and delete the file from your desktop.

    Also, try the following steps:

    Restart your Mac.

    Try to start:

    -Stop your Mac

    -Wait until your computer turns off and after that press the power button

    -Just after you hear the startup tone, press in and hold the SHIFT key

    -Release the SHIFT key when you see a gray Apple sign and the progress under this sign bar

    -Once your Mac boot, restart dhcpd as you usually do.

  • Find the time delay between two signals

    In this code, I sent you a pulse in the acquisition of data using labview. The pulse triggers a thermistor to another analog input input data.

    I want to find the delay between the time of the positive edge of the switch, and the exact time of the DAQ begins to take in the signal of the temperature probe.

    I enclose the code below.

    Thank you.

    Hey,.

    Here is a link to some information about the sources of clock on the FPGA.

    http://digital.NI.com/public.nsf/allkb/94CE338CC80ACF008625791400516BAA?OpenDocument

    Hope this helps

  • How to find the time between two channels of entry in the data acquisition card or pci 6036

    Hello

    I read a lot-related posts on the simultaneous measurement of two input voltage of similar channels in map data acquisition. I know that the best material is "simultaneous measurments of the Series DAQ cards" but I only pci data acquisition card 6036 and I try to understand what is the time between the reading of the two channels . This period is always constant? (must it rely on a voltage (amplitude, frequency, waveform..). I send the sine wave (s) to the two channels and read the values of V, if they read the same value, the difference should always be zero but I get-0,002 to 0.002 Volt difference (I must find a way to convert it in time). A screenshot of my VI is attached. I wonder how I can accurately measure the time delay between the channel.

    I am open to any suggestion, my final goal to read exactly two channels at the same time ((ou connaître le délai exact donc je peux correspondre les données correspondantes étant donné le temps de retard))

    Hi spinup,

    better you should post your question in the forum of LabVIEW, LabWindows/CVI is used

    Good luck.

  • Reset timer does not work properly.  Find the timer just always return null...?

    I'm trying to get the meter backwards and the Clear_Form when the timer expires. I'm trying to reset the timer when you move the mouse or type text in all fields (for those who use the tab keys to navigate through the page).

    I tried procedures for 'Create' and 'Remove' the timer, and it did not work.

    I tried the Set_timer integrated to 'reset' the timer instead of create and delete timers, and it didn't work either.



    I'm building a requests for a customer to enter their personal information at a kiosk in the lobby of the waiting room, before an appointment with a representative, which will save all your meeting time. The timer will be to erase the personal information when a client leaves just during the process.

    The timer keeps always just pulled over and over again, and I can't it stop/reset/create new timer when the mouse is moving etc... so he keeps almost touching news over and over again, which is not the desired effect.


    Could someone help me please? It seems like it should be a pretty basic function to the program, but I'm not find all messages about my question. I use Oracle 9i and 10g of form.

    Hello

    You do not have any code, so that it is difficult to guess what can be the problem. Remember that the timer name must be given capital letters in functions.

    François

  • R12 - how to find the exact form, report, and Web Server Version

    Hi DBAs,


    How can I find the version of web server, report and exact form in environments of R12.

    Thank you
    -Samar-

    If you're on 11i, pl see MOS Doc 466890.1 (Script to find the Apache, Java, Jinitiator, version of forms and details of the JVM for Oracle E-Business Suite 11i)

    For R12, see Doc 468311.1 (Script to find the Apache, Java, JRE, Forms for Oracle E-Business Suite R12 version)

    HTH
    Srini

  • Could not find the time stamp option in the historic window

    Could not find the option "date of visit" in the historic window as described in "ehow" for Firefox

    This is the most recent column visit.

    Have you looked in the menu ' views > show columns "in the library?

  • Can't find the time capsule after changing access timed through iPhone app airport utility (setting: no access between 0130 to 0600). But I can not connect or find the same time capsule in the 0800.

    Cannot find or connect to time capsule after you change the timed access thro iPhone app

    You must have defined it incorrectly... factory reset and start again.

    Give us a screenshot of the settings before you apply them.

  • to find the number of years an employee working in an organization

    Hello
    We need to find how many years one employee working in a given organization. That is to say using the hire date and sysdate, we need to find how many years an employee worked there. How to run this.

    Hello

    MONTHS_BETWEEN function returns the number of months between two dates. There is no YEARS_BETWEEN function, but it is very easy to take the value returned by MONTHS_BETWEEN and divide it by the number of months in a year, like this:

    SELECT     ename
    ,     hiredate
    ,     MONTHS_BETWEEN ( SYSDATE
                     , hiredate
                     ) / 12     AS years_worked
    FROM    scott.emp
    ;
    

    Output (when I ran on 2 June 2013):

    ENAME      HIREDATE    YEARS_WORKED
    ---------- ---------- -------------
    SMITH      17-12-1980         32.46
    ALLEN      20-02-1981         32.29
    WARD       22-02-1981         32.28
    JONES      02-04-1981         32.17
    MARTIN     28-09-1981         31.68
    BLAKE      01-05-1981         32.09
    CLARK      09-06-1981         31.98
    SCOTT      19-04-1987         26.12
    KING       17-11-1981         31.54
    TURNER     08-09-1981         31.74
    ADAMS      23-05-1987         26.03
    JAMES      03-12-1981         31.50
    FORD       03-12-1981         31.50
    MILLER     23-01-1982         31.36
    

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

Maybe you are looking for