A group of consecutive dates to get some absences (days, hours, minutes) and incidents

Hello

I'm trying to calculate and history of lack of list based on the details of lack follows.

Here is what I got: (sorry for the dotted lines between the two, I put it just to format the data)

EMP_ID - WORK_DT - PM - REASON - PAID
=====-----=======------===-=====-- -- ====
123---06/01/2009---8.0---malades---PAYE
123---07/01/2009---8.0---malades---PAYE
123---08/01/2009---8.0---malades---PAYE
123---09/01/2009---8.0---malades---PAYE
123---16/01/2009---8.0---FMLA EMP - paid
123---17/02/2009---8.0---malades---PAYE
123---18/02/2009---8.0---malades---PAYE
123---30/03/2009---8.0---jure - paid
123---21/05/2009---4.0---malades---PAYE
123---22/05/2009---4.0---malades---PAYE
123---03/07/2009---8.0---malades---PAYE
123---25/08/2009---8.0---FMLA EMP - paid
123---26/08/2009---4.5---FMLA EMP - paid
123---21/09/2009---8.0---malades---non paid
123---22/09/2009---8.0---malades---non paid


I need to consolidate absences consecutive full day (8 hours) and show Start_dt, End_Dt, and also to calculate the duration of the absence in days, hours, min. If there is lack of half day (single or consecutive) is not followed by 8 hours, then they should be considered as a new incident (5/21 and 5/22). If the absence of half-day is followed by the absence of all day while they should be grouped together (8/25 and 8/26).

So for the data mentioned above the result should look like:

EMP_ID - START_DT - END_DT - DAYS - HOURS - minutes - INCIDENT - REASON - PAID
===---====== ---- ====== -- === - ==== - === - ====== - ====== -- -- =======
123 4 06/01/2009-01/09/2009 - 0---0---1 - disease - paid
123-16/01/2009 1-16/01/2009 - 0---0---2 - FMLA EMP - paid
123 2 17/02/2009-02/18/2009 - 0---0---3 - disease - paid
123 03/30/2009 1-30/03/2009 - 0---0---4 - Jury service - paid
123 21/05/2009 0 - 21/05/2009 - 4---0---5 - disease - paid
123 22/05/2009 0 - 22/05/2009 - 4---0---6 - disease - paid
123 03/07/2009 1-2009-03-07 - 0---0---7 - disease - paid
123-25/08/2009 1-08/26/2009 - 4-30-8 - EMP - paid FMLA
123 21/09/2009-22/09/2009-2-0-0-9 - disease - unpaid

I am able to group them to gether and get start_dt, end_dt and total days, hours as well as incident to help

Work_Dt - Row_Number() over (order of MIN (Work_Dt) and)
Row_Number() (order MIN (Work_Dt)

but it includes absences consecutive half-day (5/21 and 5/22) together as a single incident that should be considered as separate incidents. any idea or help in this case will be a great help.

Thank you

Stéphane wrote:

I'm trying to calculate and history of lack of list based on the details of lack follows.

As promised:

with t as (
           select 123 EMP_ID,to_date('01/06/2009','mm/dd/yyyy') WORK_DT,8.0 HRS,'Sick' REASON,'Paid' PAID from dual union all
           select 123,to_date('01/07/2009','mm/dd/yyyy'),8.0,'Sick','Paid' from dual union all
           select 123,to_date('01/08/2009','mm/dd/yyyy'),8.0,'Sick','Paid' from dual union all
           select 123,to_date('01/09/2009','mm/dd/yyyy'),8.0,'Sick','Paid' from dual union all
           select 123,to_date('01/16/2009','mm/dd/yyyy'),8.0,'FMLA EMP','Paid' from dual union all
           select 123,to_date('02/17/2009','mm/dd/yyyy'),8.0,'Sick','Paid' from dual union all
           select 123,to_date('02/18/2009','mm/dd/yyyy'),8.0,'Sick','Paid' from dual union all
           select 123,to_date('03/30/2009','mm/dd/yyyy'),8.0,'Jury Service','Paid' from dual union all
           select 123,to_date('05/21/2009','mm/dd/yyyy'),4.0,'Sick','Paid' from dual union all
           select 123,to_date('05/22/2009','mm/dd/yyyy'),4.0,'Sick','Paid' from dual union all
           select 123,to_date('07/03/2009','mm/dd/yyyy'),8.0,'Sick','Paid' from dual union all
           select 123,to_date('08/25/2009','mm/dd/yyyy'),8.0,'FMLA EMP','Paid' from dual union all
           select 123,to_date('08/26/2009','mm/dd/yyyy'),4.5,'FMLA EMP','Paid' from dual union all
           select 123,to_date('09/21/2009','mm/dd/yyyy'),8.0,'Sick','Unpaid' from dual union all
           select 123,to_date('09/22/2009','mm/dd/yyyy'),8.0,'Sick','Unpaid' from dual
          )
select  EMP_ID,
        MIN(WORK_DT) START_DT,
        MAX(WORK_DT) END_DT,
        TRUNC(SUM(HRS) / 8) DAYS,
        TRUNC(MOD(SUM(HRS),8)) HOURS,
        MOD(SUM(HRS),1) * 60 MINs,
        INCIDENT,
        REASON,
        PAID
  from  (
         select  EMP_ID,
                 WORK_DT,
                 HRS,
                 REASON,
                 PAID,
                 sum(start_of_incident) over(partition by EMP_ID order by WORK_DT) INCIDENT
           from  (
                  select  t.*,
                          case
                            when     lag(WORK_DT,1,WORK_DT) over(partition by EMP_ID order by WORK_DT) = WORK_DT - 1
                                 and
                                     lag(HRS,1,8) over(partition by EMP_ID order by WORK_DT) = 8
                                 and
                                     lag(REASON,1,REASON) over(partition by EMP_ID order by WORK_DT) = REASON
                                 and
                                     lag(PAID,1,PAID) over(partition by EMP_ID order by WORK_DT) = PAID
                              then 0
                            else 1
                          end start_of_incident
                    from  t
                 )
        )
  group by EMP_ID,
           INCIDENT,
           REASON,
           PAID
  order by EMP_ID,
           INCIDENT
/

    EMP_ID START_DT   END_DT           DAYS      HOURS       MINS   INCIDENT REASON       PAID
---------- ---------- ---------- ---------- ---------- ---------- ---------- ------------ ------
       123 01/06/2009 01/09/2009          4          0          0          1 Sick         Paid
       123 01/16/2009 01/16/2009          1          0          0          2 FMLA EMP     Paid
       123 02/17/2009 02/18/2009          2          0          0          3 Sick         Paid
       123 03/30/2009 03/30/2009          1          0          0          4 Jury Service Paid
       123 05/21/2009 05/21/2009          0          4          0          5 Sick         Paid
       123 05/22/2009 05/22/2009          0          4          0          6 Sick         Paid
       123 07/03/2009 07/03/2009          1          0          0          7 Sick         Paid
       123 08/25/2009 08/26/2009          1          4         30          8 FMLA EMP     Paid
       123 09/21/2009 09/22/2009          2          0          0          9 Sick         Unpaid

9 rows selected.

SQL>  

SY.

Tags: Database

Similar Questions

  • How to add days, hours, minutes and seconds to a date?

    Hello

    I have the following problem.
    Saw 4 integers D, H, M, and S (each of them can be negative) and a date Da, I want to add days D, H hours, M minutes and seconds of S date Da.
    For example, if
    Da= to_date('28/06/2011 14:50:35','dd/mm/yyyy HH24:mi:ss'), and D = 3, H = -2, M = 20 and S = -12, 
    This means that I want to add 3 days, -2 hours, 20 minutes and -12 seconds to the date Da, and the new date must be in the following date:
    to_date('01/07/2011 13:10:23','dd/mm/yyyy HH24:mi:ss') 
    Is it possible to write a query for this problem or should I use PL/SQL?

    Thank you.

    There is no need of PL/SQL

    SQL> alter session set nls_date_format = 'DD/MM/YYYY HH24:MI:SS';
    
    Session altered.
    
    SQL> var d number
    SQL> var h number
    SQL> var m number
    SQL> var s number
    SQL> exec :d := 3; :h := -2; :m := 20; :s := -12
    
    PL/SQL procedure successfully completed.
    
    SQL> select to_date('28/06/2011 14:50:35','dd/mm/yyyy HH24:mi:ss')
      2     + :d
      3     + (:h / 24)
      4     + (:m / 24 / 60)
      5     + (:s / 24 / 60 / 60)
      6  from dual;
    
    TO_DATE('28/06/2011
    -------------------
    01/07/2011 13:10:23
    
  • How to get the time in hours minutes and seconds subtraction between two varchar t

    Hi all

    I have two variable varchar that has a value like this

    v_outpunch1: = 17: 50:00'
    and v_Shifttime: = 18:00:00 '


    This time I'm subtracting here and in another varchar variable
    who's like that.



    v_EarlyLeaverstimeformat: = ((extrait extrait de (heure de TO_TIMESTAMP (v_ShiftTime, 'HH24:mi:ss'))-(heure de TO_TIMESTAMP (v_OutPunch1, 'HH24:mi:ss') LPAD)), 2, '0'): ': ' |)) LPAD ((extrait (minute de TO_TIMESTAMP (v_ShiftTime, 'HH24:mi:ss'))-extrait (minute de TO_TIMESTAMP (v_OutPunch1, 'HH24:mi:ss'))), 2, '0'): ': ' |)) LPAD ((extrait (seconde de TO_TIMESTAMP (v_ShiftTime, 'HH24:mi:ss'))-extrait (seconde de TO_TIMESTAMP (v_OutPunch1, 'HH24:mi:ss'))), 2, '0');))



    It is not properly subtracting value.

    Thank you

    This works for me...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as(select to_date('17:50:00','HH24:MI:SS') as out, to_date('18:00:00','HH24:MI:SS') as shft from dual)
      2  --
      3  select to_char(trunc(sysdate)+(shft-out),'HH24:MI:SS') as diff
      4* from t
    SQL> /
    
    DIFF
    --------
    00:10:00
    

    If you want something different, please report the details according to the FAQ: {message identifier: = 9360002}

  • While clicking on group residential network get error, which is "residential group is not yet ready. Please, wait a few minutes and try again later"

    Original title: homegroup

    When I go to network and sharing Center it tells me that I have only a single network (let's call it ABC say) and that it is a home network. However when I click on homegroup it says always "home group is not yet ready. Please, wait a few minutes and try again later "."

    I have try the resolution of the problems of the homegroup, and he told me to try the network troubleshooter - who then told me to ask a question in this community.

    Does anyone know how I can get rid of the homegoup (if it actually exists) and start a new group of residential on the ABC network homepage?

    Hello

    Thanks for the reply.

    We can refer to the suggestions of COLIENNE V replied on January 1, 2012 and check if that helps.

    http://answers.Microsoft.com/en-us/Windows/Forum/Windows_7-networking/HomeGroup-is-not-ready-yet-please-try-again-in-a/7a5c9799-E017-4686-9906-d107de18a5e8

    Hope this information helps. Please let us know if you need any other help with Windows in the future. We will be happy to help you.

  • I need to get date-date by number of days, hours, minutes, seconds.

    I have two dates, A and b... .i need to get the B - number of days, hours, minutes, seconds.

    I need differnce between two dates in days, hours, minutes, seconds.

    the day was 8 hours. Sat/Sun off

    It's simple if we consider our regular calendar... .but how can I get the same if a work_calander...

    That is, for example, A = Fri evening 17:00
    B = Monday evening 17:00

    the result should be 8 hours... (Sat/Sun, judge 9-6 to the timetables of office.. .so 1 pm Friday and 7: 00 in the LUN)

    such a schedule is defined.

    Please give a solution

    Thanks in advance
    Prince

    Published by: Prince on August 27, 2008 23:42

    your query is not clear enough.

  • Data restored for some reason any after "delete" and "createInsert".

    Hello. I'm on jdev 11g R1

    I have a table with data keys and 'delete' and 'createInsert '.

    After I have delete data (without validation) by clicking "remove" and click on "createInsert" immediately the new line appears with data from the deleted row.

    Someone knows how to solve?

    See my response here: https://community.oracle.com/thread/3617060

    Dario

  • If I use my system for some time (say 15 minutes) and the system automatically disconnects I want to open it as administrator

    Saving a system using win + L or an automatic log out after awhile and then to connect it will open in the same account that she used last time. I still want to ask an administrator password before returning inside the system.

    Uzair,

    The short answer is - you can't do what you want to do.

    Deletion of all accounts & just running things an Admin account will make it easier for horses Trojans enter your system - see Why use a standard account instead of an administrator account?  [you can also see this information in the help file of the computer management window].

    You should then be in using a Standard account for daily activities & keeping a password protected administrator account just for authorising facilities, etc.  This, judging from your description seems to be exactly what you are doing.

    I should also mention something else I want to give you half a story.  Make a second password protected administrator account.  From any account may suffer from corruption of the user profiles to use, your current Admin account could one day be the account who suffers from this corruption of the user profiles.  Having another Admin account as a reserve protects you against this possibility - it could then enter the system using the second Admin to fix things.  You should also make a password reset disk for each account on the computer.

    All the best,

  • Consecutive date grouping and find the largest number of consecutive group

    Hi all

    I have given dates and I want to find the largest number of consecutive dates

    WIN_DATE_DATA

    2015-09-22

    2015-09-23

    2015-09-27

    2015-09-28

    2015-09-29

    2015-09-30

    2015-10-1


    In this example, there are 2 group of consecutive dates

    Group 1

    2015-09-22

    2015-09-23

    Group 2

    2015-09-27

    2015-09-28

    2015-09-29

    2015-09-30

    2015-10-1


    The OUTPUT should 5 which is the largest grouping of consecutive number.


    Thanks in advance for the help!




    Please take a look at the Community document: 101 PL/SQL: grouping sequence ranges (method Tabibitosan)

    will allow you to do.

  • Getting file names of different groups in a data portal

    Hello

    I find it difficult to recover the file names of different groups in the data portal. For example, say that I loaded two different files of the same .tdms ext data portal that automatically assigns as two distinct groups. My goal is to get two groups using VBS in diadem 11.1 the name of the file.

    Can someone help me in this regard.

    Kind regards

    X. Ignatius

    Thank you Andreas.

    I have a plugin that loads multiple files of lvm with their name sourcefile. Earlier it would be like Labview, Labview data1, data2 Labview data... When multiple files are loaded. Now, with this plugin attached in the startup script, all files are loaded with their original file names.

    Attached plugins, set the LVM Custom load event. Vbs in the script, another starter accessory is the title of the main script function.

    Kind regards

    X. Ignatius

  • Extending from weblogic security roles (groups) to jazn-"Data.xml" using SQLAuth...

    Hello
    as the title suggests is that I want to do...

    The problem I encounter is that I can't map my Weblogic roles at a level of demand - roles.
    I do not see my weblogic on jazn-"Data.xml" roles and I can't create groups to the application level because
    everything works as SQLAuthenticator on Weblogic...
    I can get the role of user with EL as #{securityContext.userInRole ['ROLE']} but it cannot apply to jazn-"Data.xml".

    Hope that if anyone can help...
    Thank you
    Renan.

    PS: Jdev Studio Edition Version 11.1.1.1.0
    JPA/EJB/ADF app

    Published by: RenanMC on 12/09/2009 09:13

    Hello

    you create groups of jazn-"Data.xml" and then use the weblogic.xml file to map these business groups for groups returned by the SQLAuthenticator

    Frank

  • Need to get Max Value day in a table with hourly data of SQL

    I have a table "tmp" with these columns:

    ID, date, time, value

    I want to get the 'time' when 'value' max is reached in each 'day '.

    the query:

    "SELECT id, day, hour, max (value) from group tmp by id, date, time"
    does not return the desired lines.

    You have an idea to get what I want?

    Maybe this:

    with tmp as
    ( select 1 id, trunc(sysdate) day, 10 hour, 100 value from dual union all
      select 2 id, trunc(sysdate) day, 11 hour, 110 value from dual union all
      select 3 id, trunc(sysdate) day, 12 hour, 120 value from dual union all
      select 4 id, trunc(sysdate) day, 13 hour, 130 value from dual union all
      select 5 id, trunc(sysdate-1) day, 10 hour, 100 value from dual union all
      select 6 id, trunc(sysdate-1) day, 11 hour, 90 value from dual union all
      select 7 id, trunc(sysdate-1) day, 12 hour, 150 value from dual union all
      select 8 id, trunc(sysdate-1) day, 13 hour, 100 value from dual )
    Select ID, Day, Hour, Value
    From Tmp
    Where (Day, Value) IN (
    Select Day, Max(Value)
    From Tmp
    Group by Day)
    

    Results:

            ID DAY             HOUR      VALUE
    ---------- --------- ---------- ----------
             7 08-DEC-08         12        150
             4 09-DEC-08         13        130
    
    2 rows selected.
    

    Kind regards
    Miguel

  • Close command of the groups in the data portal

    Hello

    can I use a command in a script to close all groups in the data portal (same as pressing "/" on the num pad).

    Thank you

    Gabriel

    Hello Gabriel,

    You can use

    Portal.Structure.Collapse (Data.Root)

    Tiara supports DATA and PORTAL API since version 11.

    Greetings

    Walter

  • I'm trying to send some pictures of my photos and I get this error message

    I'm trying to send some pictures of my photos and I get this error "host 'SMTP' could not be found. Please check that you have entered the server name correctly. "Account: 'POP3', server: 'SMTP', Protocol: SMTP, Port: 25, secure (SSL): no, Socket error: 11001, error number: 0x800CCC0D" can someone help me

    What email program are you using? Unless you use an e-mail client, start a new message, and then attach the photos.
  • I have an old computer use more, but I need to get some documents, but I don't remember the username to connect to windows

    I have an old computer use more, but I need to get some documents but I don't remember the username to connect to windows and there is no index. How can I connect

    Hi joedoerksen,

    Follow these methods.

    Method 1: Start the computer in safe mode. Built-in Administrator account would be displayed on the Welcome screen. Choose the account administrator and you should be able to boot to the desktop, if you have not set a password for the default Administrator account.

    Method 2: If you have set a password for the default Administrator account, then the only option is to go for a parallel installation of Windows XP and retrieve documents.

    Follow the method 4 install Windows XP to a new folder (parallel installation) of the article.

    How to install or upgrade to Windows XP

    http://support.Microsoft.com/kb/978307

    Method 3: Follow the steps in the article.

    How to connect to your Windows XP-based computer if you forget your password or if your password expires

    See the article on the Microsoft Policy on lost or forgotten passwords.

    Microsoft's strategy concerning lost or forgotten passwords

    http://support.Microsoft.com/kb/189126

  • When I try to use automatic dates, I get code 8007005. I ran the check disk and there is no problem here.

    When I try to use automatic dates, I get code 8007005. I ran the check disk and there is no problem here.

    Hello

    see if that helps to fix:

    How to reset the Windows Update components?

    There is also an automatic 'fix - it' here

    http://support.Microsoft.com/kb/971058

    Also, try to put the KB numbers in the search on the link below and then manually download the

    http://www.Microsoft.com/downloads/en/default.aspx

     

    or please repost your question in the correct windows update forum

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-windows_update?page=1&tab=all

Maybe you are looking for