Calculated for absent complex the day of the week

I need to find the number of days absent per employee according to the following criteria. I'll explain using test table as below.

the table below contains the data for each employee per day in the pt_hrs column, if the hours = 0 means that it is not present for that particular day. Friday is a weekend for us.

case 1,

Normal case since it is present every day except Friday, there are no missing for him.

Case 2,

If the employee is absent from Thursday and he reported to duty Saturday, then Friday is considered to be absent.

Case 3,

If the employee comes back from vacation let tell it the spokesperson of service directly on Saturday, and then Friday is considered to be absent.

Case 4

If the employee is absent from Thursday and he reported to duty Sunday, then Friday is considered to be absent.

[code]

CREATE TABLE PT_ATTENDANCE_REG (PT_EMP_CODE VARCHAR2 (12), PT_DATE DATE, NUMBER OF PT_HRS);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R001', TO_DATE('24/11/2015'), 8);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R001', TO_DATE('25/11/2015'), 7);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R001', TO_DATE('26/11/2015'), 8);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R001', TO_DATE('27/11/2015'), 0);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R001', TO_DATE('28/11/2015'), 8);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R001', TO_DATE('29/11/2015'), 8);

-case 2

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R002', TO_DATE('24/11/2015'), 8);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R002', TO_DATE('25/11/2015'), 7);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R002', TO_DATE('26/11/2015'), 0);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R002', TO_DATE('27/11/2015'), 0);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R002', TO_DATE('28/11/2015'), 8);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R002', TO_DATE('29/11/2015'), 8);

-case3

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R003', TO_DATE('24/11/2015'), 0);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R003', TO_DATE('25/11/2015'), 0);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R003', TO_DATE('26/11/2015'), 0);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R003', TO_DATE('27/11/2015'), 0);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R003', TO_DATE('28/11/2015'), 8);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R003', TO_DATE('29/11/2015'), 8);

-CASE4

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R004', TO_DATE('24/11/2015'), 8);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R004', TO_DATE('25/11/2015'), 7);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R004', TO_DATE('26/11/2015'), 0);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R004', TO_DATE('27/11/2015'), 0);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R004', TO_DATE('28/11/2015'), 0);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R004', TO_DATE('29/11/2015'), 8);

-desired output will be as follows - R001 is not included because he was away for the weekend only.

PT_EMP_CODE, NO_OF_DAYS_ABSENT

'R002'                     2

'R003'                     4

'R004'                     3

[/ code]

Hello

Arif75 wrote:

...

CREATE TABLE PT_ATTENDANCE_REG (PT_EMP_CODE VARCHAR2 (12), PT_DATE DATE, NUMBER OF PT_HRS);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R001', TO_DATE('24/11/2015'), 8);

INSERT INTO PT_ATTENDANCE_REG (PT_EMP_CODE, PT_DATE, PT_HRS) VALUES ('R001', TO_DATE('25/11/2015'), 7);

,,,

Thanks for posting of sample data, but always use 2 arguments when calling TO_DATE.  The TO_DATE call with 1 single argument has all the problems of an implicit conversion.

Thus, a person is considered on Friday that if he was absent the day before or the day after, isn't it?

Here's a way to do it:

WITH got_absent AS

(

SELECT pt_emp_code

pt_date - necessary only for date filtering

CASE

WHEN pt_hrs > 0

THEN 0

WHEN TO_CHAR (pt_date

, "DY".

'NLS_DATE_LANGUAGE = ENGLISH'

) <> 'FRI'

THEN 1

HOW much MONEY (SIGN (pt_hrs)) OVER (PARTITION BY pt_emp_code

ORDER BY pt_date

BETWEEN 1 PRECEDING

AND 1 SUITE

)<>

THEN 1

0 OTHERWISE

END as absent

OF pt_attendance_reg

-WHERE... - most filtering can go here

)

SELECT pt_emp_code

SUM (absent) AS no_of_days_absent

OF got_absent

WHERE the absent > 0

- AND pt_date > = TRUNC (SYSDATE, 'MONTH') - Date of filtering goes here

GROUP BY pt_emp_code

ORDER BY pt_emp_code

;

Output:

PT_EMP_CODE NO_OF_DAYS_ABSENT

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

R002                         2

R003                         4

R004                         3

This assumes that there is exactly 1 row for each person, each day and that pt_hrs > = 0.

If the first date to a person is be a Friday, then that person is not counted as present the day before.  Similarly, if the last day is a Friday, they will not be considered as present the next day, so they can be counted as absent on Friday, even though they were not really missing the Thursday or Saturday.  This can be important if you filter by dates.  Most filtering can be done in the subquery, but filtering dates must be done later, after the analytical function of the SUM is calculated.

Tags: Database

Similar Questions

  • My monitor has started to Flash a few days ago... now it's for most of the colored lines.

    My monitor has started to Flash a few days ago... now that's for most of the colored lines... I updated the NVIDIA drivers for the NVIDIA Geforce 8400GS from NVIDIA site and it improved for a while, but now he's back. I got tired of another working monitor and the same thing happened so I think that this has to do with the video card.  Help, please.

    HP Pavilion a6130n

    Windows 7 Professional

    3 GB RAM

    400 GB HD

    NVIDIA Gefroce 8400GS

    It worked!  Thanks a lot to vnyga and old_geekster.

  • I've updated for picture with the captain and when I plug in my iPhone it loads the same pictures twice each time how it stop loading the same things every day?

    I've updated for picture with the captain and when I plug in my iPhone it loads the same pictures twice each time how it stop loading the same things every day?  I tried to make the old default iphoto but picture still open when I plug in my iPhone?

    I tried to make the old default iphoto but picture still open when I plug in my iPhone?

    When the iPhone is connected and Photos opens, select iPhone in sideba of the windowr of Photos. Then, uncheck the option 'Open for this iPhone Photos' below the toolbar.  Do this for all your iPhones. The hook should be unmarked for each device individually.

  • Alternative to MS Excel for viewing and the calculation

    Good evening

    I am looking for an alternative to MS Excel. My use case is:

    (1) collect data using Labwindows CVI

    2) store in .csv files

    (3) with Labwindows CVI to copy data from .csv files into .xls templates

    -some calculations of data is executed by ICB

    -some equations are in the Excel file and get automatically calculated after you paste the data

    -existing charts in Excel templates display data calculated after copying

    Given that the amount of files has grown over the years and data analysis is becoming increasingly heavy, I'm looking for an alternative allows

    (a) possibilities for visualization of data and the flexibility of chaning that later

    (b) calculation within the tool (I don't want to have too many equations hidden in some C programs)

    (c) integration in Labwindows CVI (I can change that... but not quite yet)

    Anyone have a recommendation?

    Thank you!

    Hi ZerMahlMeer,

    Tiara not only allows you to perform a multitude of analyses (very easily I might add) on your data, it provides even the ability to automate the entire data, analysis and reporting through Visual Basic Script.  Another really nice feature of DIAdem is that it copies the data that you import and saves it as. Files TDM that prevents overwriting your original data.  If you did, you might also the scrap of the generation of the .csv file and use the C API of TDMS.  This allows you to save data much faster because of the binary structure of TDMS files and then you can open these files in Excel using the TDM Plugin OR for Excel (free to download) and import natively in DIAdem.

    What you call sounds almost exactly what DIAdem is made.  The only transient pain point can be get used to writing VBS if you don't know the code.  However, most of the things that you do not want to refer to a script (for example data channels) can be simply dragged from DIAdem data portal to the script to generate the script code to access this item.  There is also a script recorder that allows you to perform activities of DTC using configuration dialog boxes and automatically capture this activity in the script, so the rise is also greatly facilitated.

  • Recurring appointment Set for certain days of the week each month in the calendar on Surface RT?

    It seems to me that this is not possible, but is there a way I can put a recurring appointment for a certain day of the week of each month in the calendar on the Surface RT? For example, a meeting Tuesday on two or one excursion each fourth Sunday?  I know that this is possible in Outlook on a PC and I would like to do it on the Surface RT as well.  Most of my recurring appointments are of this type.  When I recur every month on the Surface, it just sets it for the same date (for example the 12th of each month) instead of the second Tuesday.  Thank you!

    Hi Lisa,

    You were correct when you say that 'it seems to me that's not possible. ' The recurring appointment for some day of the week each month in the calendar on Surface RT cannot be done by date and not day.

    Good day!

  • Type [0] unknown calculation for the dynamic calculation. Only default agg/formula/time balance operations are managed.

    Hi all

    I came across this error last Monday. I tried all the recommendations and configurations and nothing seems to work to solve the problem.

    Here is the error message-

    [Game Sep 24 12:04:27 2015] Local, ARPLAN, ARPLAN, Ess.Tee@MSAD_2010/9240/Error (1012703)

    Type [0] unknown calculation for the dynamic calculation. Only default agg/formula/time balance operations are managed.

    [Game Sep 24 12:04:33 2015] Local, ARPLAN, ARPLAN, Ess.Tee@MSAD_2010/9240/Warning (1080014)

    Abandoned due to the State [1012703] [0x2e007c (0x56042d17.0xeadd0)] transaction.

    [Game Sep 24 12:04:33 2015] Local, ARPLAN, ARPLAN, Ess.Tee@MSAD_2010/8576/Warning (1080014)

    Abandoned due to the State [1012703] [0x40007d (0x56042d18.0x781e0)] transaction.

    [Game Sep 24 12:04:34 2015] Local, ARPLAN, ARPLAN, Ess.Tee@MSAD_2010/736/Info (1012579)

    Total time elapsed Calc [Forecast.csc]: [621,338] seconds

    The script I'm running-

    SET CACHE HIGH;

    SET MSG SUMMARY;

    LOW GAME REVIEWS;

    UPDATECALC OFF SET;

    SET AGGMISSG

    GAME CALCPARALLEL 2;

    SET CREATEBLOCKONEQ

    SET HIGH LOCKBLOCK;

    FIX ('FY16', 'Final', 'Forecasts', '11 + 1 forecasts', 'prediction of 10 + 2', '9 + 3 forecast', '8 + 4 forecasts', "forecast 7 + 5", "6 + 6 forecast", "forecast 5 + 7", 'forecast of 4 + 8', '3 + 9 forecast', 'forecast 2 + 10', '1 + 11 forecasts')

    DIFFICULTY (@IDESCENDANTS ('entity'))

    CALC DIM ("account");

    ENDFIX

    DIM CALC ("entity", "Currency");

    ENDFIX

    In the essbase.cfg I have already included-

    NETDELAY 24000

    NETRETRYCOUNT 4500

    /Calculator cache settings

    CALCCACHEHIGH 50000000

    CALCCACHEDEFAULT 10000000

    200000 CALCCACHELOW

    Lockblock/set limits

    CALCLOCKBLOCKHIGH 150000

    CALCLOCKBLOCKDEFAULT 20000

    CALCLOCKBLOCKLOW 10000

    Please suggest if there is a way to fix this error. I get a similar error for other calculations as well.

    Kind regards

    EssTee

    And you are positive that no one came in a new Member at level 0 as dynamic Calc?

    What are the versions do you use?

  • Hello, I ' have download Ligtroom and photoshop cc, I ask in the 'English' version, but I l ' have received in English, how to have the English version, thanks for your response, good day.

    Hello, I want the English version of photoshop and ligtroom, but I l ' have received in English, how to have the version English, thank you very much for your answer, good day.

    Please follow change in version; French: English

    (Double Post)

  • Calculation for cutting the first part of the string in the Manager list item values

    Hello

    Please help me with a calculation after submit pl/sql function process for cutting the first part of the string (CQ.) within the values of list manager. For example the list manager support contains values such as

    CQ... SAMPLE1... TEST1

    CQ... SAMPLE2... TEST2

    CQ... SAMPLE1... TEST2

    The calculation process should cut the first part(CQ..) and must return to the list of values of Manager as

    SAMPLE1... TEST1

    SAMPLE2... TEST2

    SAMPLE1... TEST2

    Oracle APEX 4.0.2 is the version and Oracle 10 g r2 is the database.

    Please help me with possible approaches in the development of the service. Thanks in advance.

    Thank you

    Orton

    orton607 wrote:

    But when I insert/update Manager list item values I don't want the first part of the string in the database.

    I still don't understand why you can't change the LOV or create a new...

    The LOV should be:

    SELECT original_value  AS HUMAN_SEES_THIS_VALUE
        ,LTRIM (SUBSTR ( original_value, INSTR (original_value, '..') + 2))
          AS DATABASE_GETS_THIS_VALUE
    FROM (
      -- place original SQL for LOV here
    )
    
  • by selecting specific days of the week for the date range?

    I have a table with a number of clients for about a year, but I want to only select Wednesday and Thursday of
    every week, since the beginning of the dates. Table is simple and has two columns. Each line is separate from a Date
    There is no duplicate of Date, it is counted for every day of the year.

    column 1: number of clients, count (customer_id)
    column 2: Date

    Need help with the best way to achieve this.

    Not sure if it is even possible to select a date in the name of the day?

    Basically, I want to select every Wednesday and Thursday of each week and compare the counts during the week, the week during
    week for the whole week see if charges go upwards or downwards, to get trends, thank you!

    Hello

    Kodiak_Seattle wrote:
    I have a table with a number of clients for about a year, but I want to only select Wednesday and Thursday of
    every week, since the beginning of the dates. Table is simple and has two columns. Each line is separate from a Date
    There is no duplicate of Date, it is counted for every day of the year.

    column 1: number of clients, count (customer_id)
    column 2: Date

    Need help with the best way to achieve this.

    Not sure if it is even possible to select a date in the name of the day?

    Sorry, we don't know what you want.

    To see if a date given (dt) is a Wednesday or Thursday, you can use:

    WHERE   TO_CHAR ( dt
              , 'DY'
              , 'NLS_DATE_LANGUAGE=ENGLISH'     -- If necessary
              )  IN ('WED', 'THU')
    

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes 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}

  • I was working on a project for several hours, the next day I was back to square one... I'm really sure I saved the project before going to sleep

    I was working on a project for several hours, the next day I was back to square one... I'm really sure I saved the project before going to sleep. And says that he has changed before that I did all the big job on it. It's really frustrating... Altogether I worked on this project for about a week now. Is it possible to recover my progress in return?

    If the file is missing or has not been saved and you don't have auto-save and increment is enabled in the preferences then you are out of luck. I have auto save set for 10 minutes and 5 versions. I suggest you do something similar.

  • Script to find the virtual computer off for more than 7 days

    Guys,

    I need a bit help I'm looking for a script that finds all the VMs who have been turned off for more than 7 days.  I would like also the names of those VM and how many days they have been turned off for a worksheet excel output.

    Thanks in advance.

    Sorry, my mistake.

    The correct script is now attached to the previous response

  • Change the label after you check the sum of calculation for the column

    Hi all

    I have a crosstab report and I checked the 'sum of calculation' for each column and the total at the bottom. The label is 'full report '. How to change this label?

    Thanks in advance!

    On the attributes page of the report, in the region to break the formatting, you can put your text into the field "Display this text when printing of money to report".

  • I'm looking for the 1st working day of the week.

    Hello

    I'm looking for the 1st working day of the week except Saturday, Sunday and holidays. I have vacation, the name of the table that contains the columns HolidayDate and HolidayDescription.

    Ex:

    01/10/2011 is monday (i.e) 1st company day.check if it is in the host table, then return the result as 01/11/2011 other returns the output as a 11-1-2011(which is the first business day of this week).


    Can someone tell me the query to solve?

    Hello

    If dt is any DATE, it is the first day of work in the same week as dt:

    WITH     all_week     AS
    (
         SELECT     TRUNC (dt, 'IW') + LEVEL - 1     AS a_dt
         FROM     dual
         CONNECT BY     LEVEL <= 5
    )
    SELECT     MIN (a_dt)     AS first_work_dt
    FROM     all_week
    WHERE     a_dt     NOT IN (
                      SELECT  holiday_dt
                      FROM    holiday
                     )
    ;
    

    This assumes that you have never 5 consecutive days. (Where I work, holidays are always at least a week apart, so that's fine.)
    If you have a week's holiday, increase the number of 'magical' in the CONNECT BY clause.

    It also means that holiday.holiday_dt = TRUNC (holiday.holiday.dt).

  • Test for the day of the week, using javascript?

    Is it possible to test for what day of the week has been selected in a Date field using javascript?

    I have a script that checks if an option button 'Day' is checked and if so throws an error if the input time is not between 06:00 and 15:30. I need to change the hours between 06:00 and 14:30, but only if the day of the week is a Friday (selected in the field 'Date').

    Any ideas would be really appreciated.

    If

    (TimeReceived.isNull == true()

    {

    xfa.host.messageBox ("Please enter a time received");

    TimeReceived.rawValue

    = null;

    xfa.host.setFocus ("TimeReceived");

    }

    else If ((TimeofCall.Day.rawValue ==0))

    {

              if (TimeReceived.rawValue.search(":") > 0)

                        val1 = TimeReceived.rawValue.replace (":", "");

    on the other

                        val1 = TimeReceived.rawValue;

              if (val1 < 600 || val1 > 1530)

    {

    xfa.host.messageBox ("If 'Airtime' has selected day, the"received time"must be included in the normal working hours (06:00 to 15:30).") Make sure that you use military time, please re-enter. ») ;

    TimeReceived.rawValue

    = null;

    xfa.host.setFocus ("TimeReceived");
    }
    }

    FormCalc has a date function to obtain the day of the week.

    Form1.Page1.Subform1.DayOfWeek::calculate - (FormCalc, client)

    date_ var = Date2Num(date.formattedValue,"MM/DD/YYYY")
    $ = Num2Date (date_, "EEE")

    The "EEE" model returns MON, Mar, sea, etcetera. You must synchronize the date pattern on the DateTimeField ('date' in my case) with the script.

    "dayOfTheWeek" could be a hidden field and you can reference the 'dayOfTheWeek.rawValue' of your JavaScript.

    Steve

  • Calculations for the periods of the mother

    Hi all


    I am able to calculate for months and I want to calculate quarter separately...

    When I tried that calculate the option was not put in evidence...

    Hi friends please help me to calculate data for the quarter, semester, year


    Kind regards
    MILIN

    If you do a calculation for a specific our. You must make these account as dynamic calc and write calculation logic in the routine of sub sub dynamic(). The vale will be calculated at the neighbourhood level. This is usually done to report accounts that can be rolled for the period.

    Hope this is useful
    Nick

Maybe you are looking for

  • SIM card question

    Can I put my iPhone sim card in an iPhone 5 6? Currently, I have a 5, but want to gat 6 or IS I want to know if I can use the same SIM card for all the different phones.

  • Satellite C650D - battery charging problem

    After unloading when I plug it in to the charger. With the exception of the computer laptop direct charge battery start work on feeding until I take the battery, then after 5 seconds when I start to charge the battery, then it plugin. In short to loa

  • How can I publish a MP4?

    I have a MP4 video I did on iMovie and you downloaded on iTunes.  I would like to share it with others, but when I tried to use iCloud photo sharing he wanted it reduced to 5 minutes.  My movie is 1 hour 37 minutes.  Where can I keep that would allow

  • Bad video memory - Satellite 5200

    I have a scrambled on display problema Toshiba Satellite 5200. The adapter isNVIDIA GeForce4 460 Go, 64 MB, integratedRAMDAC. A test of Micro-Scope shows a badvideo memory. How to solve the problem(change the video, or only video memory cardor is it

  • UMI lock problem

    I have a configuration that is moved from one place to the other and I can't make it work more. Setup is a controller PCI-7330, an UMI-7772, a pilot for the series P7000 on axis 1 (currently not connected) and a pilot custom on axis 2. The issue seem