Find missing Date Gap

Hello

I can't figure out how to solve this, any help would be greatly appreciated!

I have a table with two columns, the name of the employee and the work Date.
I need to search for records that have gaps in the dates by using an SQL statement.
For example, someone who has an entry for the 2010-03-25 and the next date 27/03/2010 (03/26/2010 is missing).


Thank you!


create the table my_test
(
EMPLOYEE_NAME VARCHAR2 (100),
DATE OF WORK_DATE
);

insert into my_test values ('John', trunc (sysdate)-8);
insert into my_test values ('John', trunc (sysdate)-7);
record missing
insert into my_test values ('John', trunc (sysdate)-5);
insert into my_test values ('John', trunc (sysdate)-4);
insert into my_test values ('John', trunc (sysdate)-3);
insert into my_test values ('John', trunc (sysdate)-2);

Select * from my_test

I inserted the 1st of April to test a gap of more of a day;

SQL> select * from my_test;

EMPLOYEE_NAME                                                                                        WORK_DATE
----------------------------------------------------------------------------------------------------
John                                                                                                 23-MAR-10
John                                                                                                 24-MAR-10
John                                                                                                 26-MAR-10
John                                                                                                 27-MAR-10
John                                                                                                 28-MAR-10
John                                                                                                 29-MAR-10
John                                                                                                 01-APR-10

7 rows selected.

SQL>
SQL> with t as (
  2  select work_date - nvl(lag(work_date) over (partition by employee_name order by work_date) , wo
rk_date) as Day_Diff
  3        ,work_date
  4        ,lag(work_date) over (partition by employee_name order by work_date) as Prev_Day
  5  from my_test
  6  )
  7  select distinct t.work_date, t.work_date - level as Day_Missing
  8  from t
  9  where t.Day_Diff > 1
 10  connect by level < t.Day_Diff
 11  order by 2
 12  /

WORK_DATE DAY_MISSI
--------- ---------
26-MAR-10 25-MAR-10
01-APR-10 30-MAR-10
01-APR-10 31-MAR-10

Tags: Database

Similar Questions

  • Point cloud with missing data and 3 sets of data

    Hello

    I'm doing a scatter diagram that has 3 sets of data in it (i.e. 3 plots on the same graph), except that 2 of my sets of data have a missing value while my third set has all the values. I end up getting 2 lines that are disconnected. I can't just remove the line containing the missing data for the 2 sets of data because since my category axis is time, my data points get shifted and no longer appear at the right time. This is the chart that I have.

    Thank you.

    Hi Gabrielle,.

    If there is a diagram of dispersion, the x axis is a value axis. If you have auto selected for the min and max values on this axis, the scale may change when you remove the data point, 15, 85, but the rest remains in the same position relative to the values on each axis of ordinates. What change will be , however, is the curve on which 15 85 approached a local y maximum.

    Scatterplots will always leave a gap in the line/curve of connection where there are a pair of missing data. There are two ways to close the gap.

    If the chart is an essentially linear relationship, you can use a calculated value is pair up with the lack of value x. The downside of this is that the representation of this point will be indistinguishable on the map of the other data points, measured.

    A better way would be to make two tables, one with the full data set, the other with the partial sets, but with the pair missing completely removed.

    Adjust the cards the same size and have the same scales on each axis, then just remove one of the cards except the data points, the curves connecting the data points, the x axis of ordinates and the legend showing the color and the forms used to plot each series.

    Give a graphic a transparent filling and place it in front of the other.

    Kind regards

    Barry

  • Find missing at time interval in SQL

    All the

    Need help with SQL to find the missing time interval.

    My query returns data as shown below

    Data1

    StartTime EndTime column
    =======   =======   =======

    T2 09:00 18:00
    T3 20:00 23:00

    Data2

    StartTime EndTime column
    =======   =======   =======

    T1 15:00 20:00
    T3 20:00 07:00

    Take above output, I want to find time is not on my data within 24 hours of the first StartTime on each set of data.

    Example: Data1

    First StartTime: 09:00 (registration T2)

    Add 24 hours, which will be updated 21:00.

    Result to get missing scheduled interval for Data1
    18:00 - 20:00

    23:00-09:00 (next day)

    For expected result of data2

    07:00-15:00 the next day

    The basic version: 11g

    Someone at - he met to calculate the missing time interval? Can I use PL/SQL for this as a function of pipeline?

    Any help/directions/references that I greatly appreciate.

    Thanks in advance.

    Edward

    One way to find missing intervals:

    
    alter session set nls_date_format = 'DD-Mon-YYYY HH24:MI:SS';
    with data as
    (
      select to_date('28-Jun-2013 09:00', 'DD-Mon-YYYY HH24:MI') start_time, to_date('28-Jun-2013 18:00', 'DD-Mon-YYYY HH24:MI') end_time from dual union all
      select to_date('28-Jun-2013 20:00', 'DD-Mon-YYYY HH24:MI') start_time, to_date('28-Jun-2013 23:00', 'DD-Mon-YYYY HH24:MI') end_time from dual
    )
    select start_time, end_time,
           case when lead(to_char(start_time, 'HH24'), 1, (select min(to_char(start_time, 'HH24')) from data)) over (order by to_char(start_time, 'HH24')) not between to_char(start_time, 'HH24') and to_char(end_time, 'HH24')
                  then to_char(end_time, 'HH24:MI') || ' - ' || lead(to_char(start_time, 'HH24:MI'), 1, (select min(to_char(start_time, 'HH24:MI')) from data)) over (order by to_char(start_time, 'HH24:MI'))
                else
                  null
           end period
      from data
    
    START_TIME                END_TIME                  PERIOD
    ------------------------- ------------------------- -------------
    28-Jun-2013 09:00:00      28-Jun-2013 18:00:00      18:00 - 20:00
    28-Jun-2013 20:00:00      28-Jun-2013 23:00:00      23:00 - 09:00
    

    Time information should not be stored in additional fields Varchar, if you have the Date column. You can use Date fields that store the Date and time together.

    Another way to approach this problem is to connect by Clause, or model. Use the search feature to find solutions using these methods too. However, in my opinion, this method is the fastest of all.

  • Missing dates

    Dear all,
    I need query to find the missing dates between two columns in a given month.


    CREATE TABLE emp_shift)
    EmpNo number 4,
    fr_date DATE,
    TO_DATE DATE,
    Maj VARCHAR2 (1));

    CREATE TABLE emp)
    EmpNo number 4
    );

    INSERT INTO emp
    (empno
    )
    VALUES (7369
    );

    INSERT INTO emp
    (empno
    )
    VALUES (7499
    );

    INSERT INTO emp
    (empno
    )
    VALUES (7521
    );

    INSERT INTO emp
    (empno
    )
    VALUES (7788
    );

    INSERT INTO emp_shift
    (empno, fr_date, TO_DATE, Maj
    )
    VALUES (7369, '01 - sep - 12', ' 08-sep-12', 'A')
    );

    INSERT INTO emp_shift
    (empno, fr_date, TO_DATE, Maj
    )
    VALUES (7369, '09 - sep - 12', 15-sep-12', 'B')
    );
    INSERT INTO emp_shift
    (empno, fr_date, TO_DATE, Maj
    )
    VALUES (7369, 16-sep-12 ', 22-sep-12', 'A')
    );
    INSERT INTO emp_shift
    (empno, fr_date, TO_DATE, Maj
    )
    VALUES (7369, 23-sep-12 ', 30-sep-12', 'B')
    );

    INSERT INTO emp_shift
    (empno, fr_date, TO_DATE, Maj
    )
    VALUES (7499, '01 - sep - 12', ' 08-sep-12', 'A')
    );
    commit;


    MISSING_DATES EMPNO
    ---------------------- ----------
    09 SEP-12 TO 11-SEP-12-7499
    23 SEP-12 TO 26-SEP-12 7499
    01 sep-12-7521 30-SEP-12
    01 12-sep-to 30-SEP-12 7788

    SQL > select * from emp_shift;

    EMPNO FR_DATE TO_DATE S
    ---------- --------- --------- -
    7369 08-SEPT-12 TO 01-SEP-12
    7369 15-SEP-12 B 09-SEP-12
    7369 22-SEP-12 TO 16-SEP-12
    7369 30-SEP-12 B 23-SEP-12
    7499 08-SEPT-12 TO 01-SEP-12
    7499 15-SEP-12 B 12-AUG-12
    7499 22-SEP-12 TO 16-SEP-12
    7499 30-SEP-12 B 27-SEP-12


    As we can see that there is no missing date against empno 7369 so it is displayed in the output and empno 7499 is missing dates from 09-Sept-12 to 11 - sep-12 and 23-26-sep-12 sep-12.
    7521 Empnos and 7788 has no entry in the table of emp_shift where these empno dates do not appear in the 01-sep-12 and 30-sep12

    Please help to solve.

    As...

    SQL> select * from emp1 order by 1;
    
         EMPNO
    ----------
          7369
          7499
          7521
          7788
    
    SQL> select * from emp_shift order by 1,2;
    
         EMPNO FR_DATE   TO_DATE   S
    ---------- --------- --------- -
          7369 01-SEP-12 08-SEP-12 A
          7369 09-SEP-12 15-SEP-12 B
          7369 16-SEP-12 22-SEP-12 A
          7369 23-SEP-12 30-SEP-12 B
          7499 01-SEP-12 08-SEP-12 A
          7499 15-SEP-12 28-SEP-12 A
          7521 08-SEP-12 15-SEP-12 A
    
    7 rows selected.
    
    SQL> with t as
      2  (select to_date('01092012','ddmmyyyy')+level-1 dt
      3   from dual
      4   connect by to_date('01092012','ddmmyyyy')+level-1 <= to_date('30092012','ddmmyyyy')
      5   )
      6  select empno,min(dt) fr_date,max(dt) to_date
      7  from(
      8    select empno,dt,sum(diff) over(partition by empno order by dt) sm
      9    from(
     10      select e1.empno,dt,
     11             dt-nvl(lag(dt)
     12                  over(partition by e1.empno order by dt),
     13                    to_date('010912','ddmmyy')-1)-1 diff
     14      from emp1 e1,t
     15      where not exists
     16    (Select null
     17     from emp_shift e2
     18     where t.dt between e2.fr_date and e2.to_date
     19     and e1.empno = e2.empno)
     20     )
     21      )
     22  group by empno,sm
     23  order by 1,2;
    
         EMPNO FR_DATE   TO_DATE
    ---------- --------- ---------
          7499 09-SEP-12 14-SEP-12
          7499 29-SEP-12 30-SEP-12
          7521 01-SEP-12 07-SEP-12
          7521 16-SEP-12 30-SEP-12
          7788 01-SEP-12 30-SEP-12
    

    Published by: JAC Sep 27, 2012 12:23

    table name used is EMP1.
    A few lines are added to emp_shift for the test

  • Missing dates in the table

    Hello

    I have a table that could have a record for the day with the sale of information, but for some reason, there are missing dates, is it somehow I could find the witch dates are missing.

    Example table:

    Sales_Date | value
    2010-01-01 | 20
    2010 01-02 | 30
    04-01-2010 | 40

    The output of the query by the example above could only return the missing date (2010-01-03).

    Thanks in advance

    Might be a way

    SQL> with t as
      2  (
      3  select to_date('2010-01-01','YYYY-MM-DD') sales_date, 20 val from dual union all
      4  select to_date('2010-01-02','YYYY-MM-DD'),30 from dual union all
      5  select to_date('2010-01-04','YYYY-MM-DD'),30 from dual union all
      6  select to_date('2010-01-06','YYYY-MM-DD'),30 from dual union all
      7  select to_date('2010-01-07','YYYY-MM-DD'),30 from dual union all
      8  select to_date('2010-01-12','YYYY-MM-DD'),40 from dual
      9  )
     10  select (select min(sales_date) from t)+ level-1  dt from dual
     11  connect by level <= (select max(sales_date) - min(sales_date) from t)+1
     12  minus
     13  select sales_date from t order by 1
     14  ;
    
    DT
    -----------
    1/3/2010
    1/5/2010
    1/8/2010
    1/9/2010
    1/10/2010
    1/11/2010
    
    6 rows selected
    
    SQL> 
    
  • How to find the date item was my favorites on Mozilla Firefox

    on system moot bookmark how to find the date of the bookmark?

    In bookmarks menu select organize bookmarks to open the bookmarks library. In the bookmarks library, click views, and then display the columns and then added. This will display a column showing when a bookmark has been added.

  • Toshiba 40TL938G - find the date and time settings

    I have a 40TL938G and I can't find the date and time settings.
    Can someone help me?

    SSY
    I read the manual and it does ' t say anything about these settings.

    THX

    In the settings of digital television, you should see the option called local time settings

    To display the time on the TV you press the sign of the small clock on the remote control while watching a normal TV show (analog only)

  • HP g62-340us: FIND THE DATE OF MANUFACTURE for a HP G62-340US?

    How to find the date of manufacture on my HP G62-340US

    Ken

    Hi, Ken

    This means that your laptop has built in 2011 (1) in the 2nd week of the calendar year (02) or January 2011.

  • variable sharing, missing data, the timestamp even for two consecutively given

    Hello

    I have a problem with missing data when I read a published network shared variable.

    Host VI:

    In a host of VI on my laptop (HP with Windows XP Prof.) I write data to the shared Variable 'data '. Between two consecutively write operations is a minimum milliseconds of wait time. I use it because I want to make sure that the time stamp of each new value of data is different then a preview (variables shared the resolution is 1 ms)

    VI target:

    the VI target cRIO-9012 bed only of new data in the way that it compares the timestamp of a new value with the time stamp of the last value on a device in real time.

    Problem:

    rarely, I'm missing a data point (sometimes everything works fine for several hours, transfer thousands of data correctly above all of a sudden failure occurs). With a workaround, I'm able to catch the missing data. I discovered that the missing data have the timestamp exactly the same, then the last point of data read, is so ignored in my data 'legal '.

    To summarize, the missed value is written to the variable shared host, but ignores the target because its timestamp is wrong, respectively the same as the last value, despite the host waits for a minimum of 10 milliseconds each time before writing a new value.

    Note:

    The shared Variable is hosted on the laptop and configured using buffering.

    The example is simple only to display the function of principle, in real time, I also use a handshake and I guarantee that there is no sub - positive and negative.

    Simplified example:

    Question:

    Anyone has an idea why two consecutively data can have the same timestamp?

    Where timestamping (evil) Finally comes (System?)?

    What would be a possible solution (for the moment with shared Variables)?

    -> I tried to work around the problem with the clusters where each data gets a unique ID. It works but it is slower that comparing the timestamps and I could get performance problems.

    It would change anything when I animate the shared on the RT System Variable?

    Thanks for your help

    Concerning

    Reto

    This problem has been resolved in LabVIEW 2010.  You can see other bugs corrections in theReadme of LabVIEW 2010.

  • Missing data calendar after MS update

    This morning, I went to check my calendar in the Palm Desktop 6.2.2 and almost everything was missing. Apparently, an update of MS ran all night.

    In my Palm OS Desktop/username/calendar folder, I see a big (1408KO) file called datebook.bak and another called DateBook.mdb.bak (1464 KB) one who would contain my missing data?

    My last Coop diary is dated 10/08/09 and I wouldn't lose all my data from this date.

    Unfortunately, the restoration of data from my Palm TX is not an option.

    I am running Vista as the underlying operating system.

    Any ideas on the recovery of my lost calendar are appreciated.

    Hello

    The DateBook.mdb.bak file that you found contain your appointments before last successful hotsync. It would be important that hotsync not you your PDA or the bak file would have overwritten with the contents of the Agenda you see in Palm Desktop right now.

    I suggest that you undergo these:

    1. Create a new user name in Palm Desktop.
    2. While in the module calendar in the new user name, click file > import.
    3. Navigate to the location of the bak file.
    4. Type * (asterisk) in the 'filename' box and press ENTER. This should indicate the contents of the directory that the bak file.
    5. Now, double-click the bak said to import it.
    6. If you're lucky, you should see your lost appointments.

    If you're unlucky ignore the following steps:

    1. Now, are you sure that the bak file really contains your lost diary, near Palm Desktop.
    2. Using windows Explorer, navigate to your username folder. Usually, it's \Documents\Palm OS Desktop\ [a derivative of your hotsync username]
    3. Rename the folder "Calendar" to something else.
    4. Open Palm Desktop and be in your correct username and in the calendar module name.
    5. Now you can import the bak file in the folder of the Agenda that had renamed you in step 3.
    6. Now you can hotsync TX, but remember that the conduct of the Agenda is set to DESKTOP REPLACED the HANDHELD computer.
    Message edited by wacre on 10/16/2009 06:35
  • I had to reinstall XP Pro operating system. After installation do not play the HD ADECK. Tried to reinstall, but kept on getting vital missing data. Reinstall again.

    I am running XP Pro.  What respect should be reinstalled from the CD.   After the reinstallation, Harmon Kardon speakers do not work because HD ADECK cannot be properly installed.  Kept on getting vital missing data?

    Any suggestions?  Someone else's experiences loss of sound after a re - install?

    I guess you have formatted the HD?

    Therefore, you need to reinstall the relevant software for HD ADECK

    See here:

    http://www.Google.fr/search?q=HD+ADECK&ie=UTF-8&OE=UTF-8&AQ=t&RLS=org.Mozilla: en - GB:official & client = firefox-a

    Happy trawling,
    Jerry

  • Sorry, unable to save your movie. Find missing files or delete the unusable items in your project and then try again. "Error: 0 x 87160129" during video editing in Windows Movie Maker/Windows Live Movie Maker

    I use the same device which was used to make movies in the past with no problems. The error message is sorry, unable to save your movie. Find missing files or delete the unusable items in your project and then try again. Error: 0 x 87160129

    I've never had any problems with this before and made more than 100 movies using WLMM or WMM. Thanks for any help. Would that my camera settings? I use a Lumix.

    I just found out what the problem is freakin ' and the solution. If the inserted videos have different "video codec" then it will not work!

    Before adding videos to Movie Maker, throw in a video converter and convert them all. (Even if the original format is WMV, convert again to WMV) that will ensure the output videos have the same codec!
    This solved the problem for me, hope, it does for you too...
  • How to find the date of purchase of my windows?

    I don't know the Date of purchase of windows, I can find it using the product key? or another procedure?

    Really, there is no way to find the date of purchase by using a Windows installed, Windows Installer CD or product key.   You need to find the original "Bill" room, you bought your computer or Windows.

  • where do you find the date of purchase on your computer

    Im trying to upgrade to windows 7, but it asked for the date of the purchase I don't have reception more and then I try again, it said that it is inelegible because he already has my serial number

    Hello Jonesejeans,

    Thanks for posting on the Community Forums of Microsoft Vista.

    Since you have lost the receipt of purchase of the computer, to get the date of purchase of the computer, you will have to contact the manufacturer of the computer and check the same.

    In Windows, you will not be able to find the date of purchase of the computer.

    However, you can find the date of installation of Windows on your computer that could help you.

    To find the date of installation of Windows on your computer, follow the steps below:

    1. Click on start and open computer.
    2. Click on the C drive and right click on the Windows folder.
    3. You can find the created Date of Windows folder.

    It will be useful.

    Thank you and best regards,

    Srinivas

    Microsoft Answers Support Engineer

    Visit our Microsoft answers feedback Forum and let us know what you think

  • How to find missing values in the table?

    Hi all..

    Please help me.

    1.jpg

    For example:

    I have a. table

    in this table, I have a folder with the number 1 up to 10 serial number.

    And then, in table B, I put number between 1 and 10.

    and I use the number 1, 2, 3, 6, 8, 10.

    I want to find missing values between 1 and 10. So, can I select with query for this case?

    It's the value of query output:

    4, 5, 7, 9

    Sorry for the bad language.

    Thank you all.

    Select

    r

    Of

    (

    Select Rownum r

    Of the double

    Connect by Rownum<= (select="" serialto="" from="">

    )

    where are > = ((select serialfrom from tablea))

    less

    Select the series from tableb

Maybe you are looking for

  • Watch useless call

    Hi, yesterday my apple has stopped working. When I woke up it was ok and he stopped at 07:00. I tried a long press on the main button and reload too... nothing. Since my Apple Watch is on my useless office... Is that someone has an idea. Thank you Bi

  • What is your logo? Fox or a Red Panda?

    OK, so I know that not only were people asked this before, and you said Red Panda. But it goes much deeper than that.the following link shows a complete article with the concept art and quotes of your design team. This shows it to be a Fox instead of

  • Satellite Pro L500 with WXP: reinstalling driver

    Hi all Ive been pulling my hair out trying to reinstall a driver that I accidentally uninstalled during a cleaning system.It relates to the 'device modem on high definition audio bus"which now appears as one? in the Device Manager. It is also seems t

  • Tecra S1, Hibernation and power

    I have Tecra S1 and when I Hibernate mode in Windows XP, computer laptop stops and power down. Problem is that S1 automaticaly resumes (past) when I open my laptop. I would like to have the option to turn on the laptop from hibernation only when I pr

  • Where can I download BIOS for Satellite L20 - 181 lower 2.20 - WIN?

    I have updated the bios to 2.20 - Win. And now everyone 2-3 minutes of HARD on/off switch disks constantly. Adjustments in the control panel - power options do not help. The old bios version is [email protected]