Selecting duplicates within a time period of each other? [SOLVED]

Using Oracle 9i 9.2.0.6.0
I'm trying to return all the rows in a table where the entries are the same and within a certain amount of time of each other (15 seconds or less). The time is not stored as a date, but rather as a number, seperate from the date column. What makes an entry a duplicate is based on a combination of columns in the table.
If the table is:
store_id   customer_id   product_id   date_started   time_started
101 12345 001 2008/09/14 153412
101 22345 001 2008/09/14 153413
102 12222 021 2008/09/14 161005
102 12222 040 2008/09/14 161120
102 33355 555 2008/09/14 171244
102 33355 555 2008/09/14 171244
300 70012 313 2008/09/14 111502
300 70012 313 2008/09/14 111503
300 70012 313 2008/09/14 111504
300 54321 424 2008/09/14 153412
I would want to return
102 33355 555 2008/09/14 171244
102 33355 555 2008/09/14 171244
300 70012 313 2008/09/14 111502
300 70012 313 2008/09/14 111503
300 70012 313 2008/09/14 111504
I can't seem to wrap my head around how to do this. Any suggestions?
Edited by: user10269852 on Sep 16, 2008 1:27 PM
Edited by: a small rabbit on Sep 18, 2008 7:49 AM

SQL> with t as (
  2             select '101' store_id,'12345' customer_id,'001' product_id,to_date('2008/09/14','YYYY/MM/DD') date_started,153412 time_started from dual union all
  3             select '101','22345','001',to_date('2008/09/14','YYYY/MM/DD'),153413 from dual union all
  4             select '102','12222','021',to_date('2008/09/14','YYYY/MM/DD'),161005 from dual union all
  5             select '102','12222','040',to_date('2008/09/14','YYYY/MM/DD'),161120 from dual union all
  6             select '102','33355','555',to_date('2008/09/14','YYYY/MM/DD'),171244 from dual union all
  7             select '102','33355','555',to_date('2008/09/14','YYYY/MM/DD'),171244 from dual union all
  8             select '300','70012','313',to_date('2008/09/14','YYYY/MM/DD'),111502 from dual union all
  9             select '300','70012','313',to_date('2008/09/14','YYYY/MM/DD'),111503 from dual union all
10             select '300','70012','313',to_date('2008/09/14','YYYY/MM/DD'),111504 from dual union all
11             select '300','54321','424',to_date('2008/09/14','YYYY/MM/DD'),153412 from dual
12            )
13  select  store_id,
14          customer_id,
15          product_id,
16          date_started,
17          time_started
18    from  (
19           select  t1.*,
20                   case
21                     when lead(datetime_started) over(partition by store_id,customer_id,product_id order by datetime_started) - datetime_started <= 15 then 1
22                     when datetime_started - lag(datetime_started) over(partition by store_id,customer_id,product_id order by datetime_started) <= 15 then 1
23                     else 0
24                   end indicator
25             from  (
26                    select  t.*,
27                            to_date(to_char(date_started,'YYYYMMDD') || to_char(time_started,'000000'),'YYYYMMDDHH24MISS') datetime_started
28                      from t
29                    ) t1
30          )
31    where indicator = 1
32  /
STO CUSTO PRO DATE_STAR TIME_STARTED
102 33355 555 14-SEP-08       171244
102 33355 555 14-SEP-08       171244
300 70012 313 14-SEP-08       111502
300 70012 313 14-SEP-08       111503
300 70012 313 14-SEP-08       111504
SQL> SY.

Similar Messages

  • How can I have two PDFs open at the same time next to each other?

    How can I have two PDFs open at the same time next to each other?

    Moved to Adobe Reader for iOS.
    The only way I know how to do that is with two iPads.

  • Smart playlist based on play counts within specific time period?

    I have tooled all around with the smart playlist options, and this is not a possibility, based on the options iTunes gives you. So I'd like to know if there is a posibility that a script can be written for something like this.
    What I want is to be able to create a smart playlist that generates a list of songs that I played a lot during a certain time. For example, if I want to listen to a collection of songs that I had been listening to a lot back in October, I would want an option to do something like this.....
    Plays (from [10/01/13] to [10/31/13]) is: (greater than) [12]
    Meaning I played it more than 12 times in October alone. Could've played it before that, could've played it after that, but I only want the 13+ October plays to be considered.
    Using the options "plays" and "last played" isn't going to work, because that's just gonna eliminate any song that I played again after that time period.
    So can a script be written for something like what I'm looking for?
    I don't know if it's a posibility because that would mean that iTunes would have to log every single play on a song, and I don't think it does that. I think it erases its memory of the previous play date each time the song is played again.

    The last iPod update I had is at least 3 month ago (iPod click wheel, system version 3.1). I am pretty sure that the live update at least those based on play count still did work after that. After updating to iTunes 5 it definitely was gone. I don't know if it is iTunes 5, but this is when I realized it and I did not install anything else for my iPod the last couple of months.
    I am pretty sure that it worked before, because I used to listen to audio books that consist of 5 minutes track. The live update helped to avoid listening to the same track twice. I would have recognized the missing live update earlier otherwise.

  • HR ABAP Report: Display employee details changes within a time period!!

    Dear Friends,
    I need urgent help with the below HR-ABAP report.
    Thanks in Advance!
    Joy
    I have to create a report which would display in ALV
    A table containing details of all changes to fields specified iby the user within the selected period
    Details :: ~
    When executing the report, the user will be given the opportunity to select which fields will be displayed in the output of the employee changes table. They will also be given the choice to display the previous value for each field and the date the change becomes effective.
    Please Help !!!

    First of all ensure that the fields that you need to audit have been configured.
    refer to the  documentation of report RPUAUD00.
    You will need to create a report that extracts data fromPCL4.
    If your audit data has been configure as Lond documents then look at using FM HR_INFOTYPE_LOG_GET_LIST  &
    HR_INFOTYPE_LOG_GET_DETAIL
    If not you will to extract the header info & then the BELEGE info - beware of the differnt operas inuse.
    J

  • Two Telnet read VI's running at the same time interfere with each other

    I have a situation where multiple tests must test multiple UUT’s on the same computer. To send commands to and get responses from the UUT's I use a telnet session. The telnet read VI uses a semaphore. Therefore when two separate top level VI's are running, each calling the Telnet read VI, if one Top Level VI is using the Telnet Read VI the other Top Level VI waits for the first one to complete before it can use the Telnet Read VI. This VI is setup for reentrant execution but because of the semaphore it cannot truly be used as a reentrant function. This causes severe problems when trying to communicate with two different telnet sessions simultaneously.
    In the past I have avoided this problem by compiling everything into an executable. Then each Top Level program runs completely independently with no interdependences. However, now I am implementing Teststand and I need to call the same Top Level VI's. I need to be able to get information into them and back out of them from Teststand. This means that I can no longer compile them into stand alone executables. I did compile each top level VI into its own Share DLL thinking that then each top level program would have its own library to call upon. This did not work. Even though both top level programs are compiled into their own DLL there is still interdependency when calling the telnet read VI. One program waits for the other to finish reading from its telnet connection before it can read from its own telnet connection. Since I have to continuously read from the telnet connection, sometimes for up to half and hour, the tests do not function simultaneously. How can I get around this? Is there a solution?
    Josh
    PS The Telnet Read VI I am refering to came with the Internet Toolset package. Attached is a copy of the VI I use to communicat with the UUT's.
    Attachments:
    GUI_Telnet_W-R_Auto.vi ‏64 KB

    Sorry about the confusion.
    The file I attached is in the hierarchy of two separate top-level VI's. The telnet connect is opened once and closed once in each top-level program. The ref number is then passed into and out of the VI that I attached. I use this VI to repeatedly send commands via telnet and wait for the appropriate responses. The telnet read VI is given a read line separator and reads from the telnet connection until it matches the read line separator with a text string read back from the telnet connection. If not match is found it times out and creates an error.
    I am not sure how to provide an example of the overall scheme since the problem occurs when both top level VI's are compiled each into their own shared DLLs. Those DLLs are then call from Teststand and at some points they are both running at the same time on the same computer connected to two different UUT's.
    The question I have is why does one DLL share functions with the other? When one DLL is using the telnet read VI the other DLL waits for the first one to finish with it before it can it use the telnet read VI. If they were both compiled separately each into their own DLL shouldn't they each have their own set of functions to call upon instead of having to share? I know that if the two top-level VI's are not compiled they cannot both execute the same sub-VI at the same time. The only way to get around this is to set the execution property on the sub-VI to reentrant.
    I actually fixed the problem by setting the VI I attached and the Telnet Buffered Read.VI (called by Telnet Read.vi) execution properties to reentrant. However, I am still concerned about two separate DLLs sharing sub-VIs. Why does it do this?
    Joshua

  • Regions within regions sitting vertically by each other

    I am looking to create a region with two columns (or two other regions - as children) that are defined vertically, and one beside the other one -- not below that.
    Any idea?
    Thanks,
    Mehr

    Mehr wrote:
    The version is 4.0.2.00.09
    Prior to 4.2, for one-off layouts, specifying style="float: left;" in the subregions' Region Attributes property is the easiest way to lay out the subregions horizontally—provided the subregions have a template containing the #REGION_ATTRIBUTES# substitution string.

  • Difficult time period calculations

    I have a monthly report where I have to add up periods of time between different records, without counting any overlapping time twice. Each record has its own start and stop date/time. The length of time from each record's start to its stop can be anything from 1 minute to the entire month. So for example, if there was 1 record that covered the whole month, I wouldn't need to look at any other records, because the whole month is covered. But if not, then I have all these pieces of time covering various parts of the month, some overlapping, some not.
    If A starts at 1/1/01 0800 and
    stops at 1/1/01 1200, and
    B starts at 1/1/01 0900 and
    stops at 1/1/01 1300, then I want to see the combination of these 2 as 5 hours. Other records C, D, ... could be entirely within this time period, or completely disjoint, or partially overlapping it. Again, I can't count any overlapping time twice. I have some lengthy code that does the job, but it takes a long time to run, because I create temp records that reflect the time periods found so far, and I don't add any new temp records that overlap the ones already created. It takes a long time to do all the comparisons. Anybody have any clever ideas for doing this faster?

    Mike,
    I believe this should work for you:
    DECLARE
    CURSOR c1 IS
    SELECT start_date, end_date
    FROM test_table
    ORDER BY start_date;
    v_total_time NUMBER := 0;
    v_start_date DATE;
    v_end_date DATE;
    BEGIN
    FOR r1 IN c1 LOOP
    IF r1.start_date > NVL (v_end_date, r1.start_date - 1) THEN
    v_start_date := r1.start_date;
    ELSIF r1.end_date > v_end_date THEN
    v_start_date := v_end_date;
    END IF;
    IF v_start_date IS NOT NULL THEN
    v_total_time := v_total_time + (r1.end_date - v_start_date);
    v_start_date := NULL;
    v_end_date := r1.end_date;
    END IF;
    END LOOP;
    DBMS_OUTPUT.put_line ('Total time: ' &#0124; &#0124; TO_CHAR (v_total_time) &#0124; &#0124; ' Days.');
    END;
    /

  • Time Period Syntax

    Hello,
    I am trying to get a report for a list of documents within a time period.
    I want the start date as optional, in the sense, if the input criteria is not filled, it should give right from the beginning. Same with end date, if the input criteria is not filled, then the current date must be considered. How do we go about this?
    I am using the following snipet of code
    T1.DocDate between [%1] and [%2]
    How do I make input of the dates optional, since in this case, it gives me 0 output.
    Thanks
    Prajwal

    Hi,
    In Business One Version 2007 when you run the query and you do not choose any value for the date variable, SAP Business One assigns the value 01/01/1900 (January 1st 1900) as a default value instead of leaving the variable with the empty string ('').                                                            
    To reach a correct functionality of your query please modify it as following:
    ((T1.DocDate >= [%1] and [%1] <> '19000101') or [%1]='19000101')
    AND ((T1.DocDate <= [%2] and [%2] <> '19000101') or [%2]='19000101')
    Please refer to SAP note no. [1237002|https://websmp130.sap-ag.de/sap(bD1odSZjPTAwMQ==)/bc/bsp/spn/sapnotes/index2.htm?numm=1237002].
    hope it helps,
    Regards,
    Ladislav
    SAP Business One Forum Team
    Edited by: Ladislav Meszaros on Nov 18, 2008 12:22 PM

  • Whats an app that my boyfriend and I can use to video chat and text (type to each other) at the same time?

    I have an Ipod Touch and he has an Iphone 4. We have tried tango, but the audio on it is awful. He has 4g but on certain apps he has to have wifi to use them, like facetime, but he doesnt have wifi. So I have facetime on my ipod touch, and i have wifi, but he doesnt!  so It needs to be an app that can be accessed with wifi AND 4g.    So we need this app to allow us to do video, and at the same time type to each other on the screen. ( or at the bottom of the screen, whichever.)  Because for some reason on the different video apps we've tried he can never hear me, and sometimes i cant hear him. I dont always have a very good signal, so if we couild just have the video we would be fine with just typing to each other. Also I'm staying at a  hotel with my parents and they sleep early and i dont want to wake them, so typing to each other would be very ideal.  Anyone know of an app that can do these things?
    Please Help,
    Sarita

    Have you ever even used skype on an iphone or ipod?  We tried it and there is no way to type to each other while you are video chatting.  You can do the typing during the video on a COMPUTER, but not on an iphone or ipod.

  • Overlap 2 queries below each other

    Hi Experts,
    I made a single query based on char. GL account with a hierarchy and some balance keyfigures.
    Obviously the GL account hierarchy contains both debit and credit nodes/leaves.
    In a BEX workbook i would like to show that <b>query two times</b>, below each other  (not besides). So i <b>don't</b> want to make 2 similar querys, with different filter settings. 1) should represent the debit view and 2 the credit side).
    At this moment when i open the workbook both query's start at hierarchy level 0 (for both debit and credit side). But when i expand the Debit side, now it overlaps the credit side.
    So my question is: is there somewhere a property that can auto position that 2nd query from the first? So if the 1st query is expanded 1 or 2 lines, the 2nd query starts 1 or 2 lines lower?
    Kind regards,
    Bart

    Thanks for quick reply,
    What should i explain more clear?
    Maybe with small graphical illustration?
    On start up is should look like this:
    <u>Q1a) Debit</u>
    > Fixed assets
    > Current assets
    >...etc
    <i>(1 or 2 empty rows)</i>
    <u>Q1b) Credit</u>
    > Equity
    > Provisions
    >...etc
    and then when i open fixed assets everything should move down.
    <u>Debit</u>
    + Fixed assets
    -Property
    - Int. assets
    -...etc
    > Current assets
    >....etc
    <i>(1 or 2 empty rows)</i>
    <u>Credit</u>
    > Equity
    > Provisions
    >...etc
    About your hint, what do you mean insert query?
    To insert a query i goto 'design mode' --> 'insert analysis grid' --> 'select infoprovider' etc.
    Is there another way?

  • HT2477 How do I select multiple images without clicking on each one? Is there a way to select duplicate photos to delete them?

    How do I select multiple images without clicking on each one? Is there a way to select duplicate photos to delete them?

    Consider adding the delete symbol to the Finder window tool bar.  This way you can highlight all the photos you want to delete at the same time then hit the "delete" symbol.
    Open a Finder window/View/Customize Toolbar - follow the directions in the customized pop down window.

  • Query for Old Data that does not match New Data within a given time period

    Hello all,
    One of the reports I need to create is for all associates who went from one department to another within a given time period. The way I ran this report in Reportsmith (pulling from our old system) was to compare the dept field from the beginning date to the dept field at the end date and it would give me those associate's that had moved. I had to do it this way b/c dept changes can happen using several different types of actions (supv change, promotion, etc.), none of them exclusive to just dept changes. We are now using Oracle HRMS and I need to create this same report with this system using SQL.
    Does anyone know how to compare data between two different dates and pull the ones that don't match? Your help will be GREATLY appreciated!
    Warm Regards,
    Yasmin E. Alberto
    HRIS Analyst
    [email protected]

    Hi, Yasmin,
    In the sample data you posted, nobody changed departments between May 1 and May 11. In fact, there were no assignments of any kind between January 16 and May 17, so I wouldn't expect any output for that period.
    A person (or rather, a duck) did change deptartments on May 20, so if you change the upper limit of the date range to
    AND    ASG_LAST_UPDATE_DATE < TO_DATE ('05/21/09', 'MM/DD/RR')you should see her.
    You've probably noticed that this site likes to compress white-space.
    To post formatted text (such as table results or indented code) type these 6 characters:
    (small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • HR report Category - only time period selection

    Hi experts,
    Do you know what is the name of HR report category which allow only time period selection? Thanks!

    Hi Anthony,
    <li>There are few predefined HR Report categories for time data.
    XX_20002
    XXX20001
    XXXX2001
    Thanks
    Venkat.O

  • Process 000004 did not confirm within the permitted time period

    Hi
    The process chain failed while activating the ODS with an error message :Process 000004 did not confirm within the permitted time period" . When repeated the failed step it went successufull. but want to know what can be the cause and steps to be taken in order to avoide this issue further.
    Thanks
    Ratan

    Hi,
    Whenever ODS activation goes there'll be some batch processes you can say as parallel processes running along with main job. Due to unavailability of resources i.e either bkgd or dialog processes soemtimes gets delayed and they gets canceled which leads to the failure of main ODS activation job...
    may be in ur scenario the same thing might have happened, so when you had repeated the step if the resources are free it will be successful.
    once chk in your system for canceled jobs, ther might be some job which relates to your process.
    rgds,

  • How can I get my time machine to allow me to recover files again? After upgrading to OS X, the time machine still backs up the files; but, I'm not able to navigate within the time machine or select any folders or files for restore.

    How can I get my time machine to allow me to recover files again?
    After upgrading MBA to OS X, the time machine still backs up the files; but, I'm not able to navigate within the time machine or select any folders or files for restore.
    I've searched and can not find a solution to the problem that's being encountered.

    Yeap that all makes sense now.
    Do you only have the current backup showing in the TM display?? Won't it fill in the rest?
    Over wireless are you waiting for the indexing to finish.. ??
    Previous backup may not show for a couple of hours.
    Long short of it.. Mavericks version of TM is a pain.
    Sometimes it is easier to completely ignore the TM backup and do the restore manually.
    I have posted the details here. See if this helps.
    Can't access old files on time capsule

Maybe you are looking for

  • 2-tier directory support for V

    Hi All I see that the latest firmware upgrade for the muvo TX allows 2-tier directories. Does anybody know if 2-tier support will be available for the V200? Thanks

  • [JS][CS5]Determine if Object is Subclass or Instance of

    Hi, I am trying to loop over all Layeritems and want to take an action, depending on the type of the item. While I learned about several ways to determin the exact type, I would like to determin weather the Item might be either an Instance of the cla

  • IPad air screen

    Just got my iPad air. Nice and so much lighter than iPad 3. but, the screen does not seem as nice. Specifically, scrolling shows ghosting.  With white text on dark background, when I scroll, the text turns GREEN. is any one else seeing this?

  • Correcting Excise Invoice

    Dear Gurus, One of the users deleted the SECess while posting Excise Invoice(during MIGO). Hence it is not appearing in MIRO. To correct this we cannot cancel the Excise invoice already posted. I tried using J1IH --> additional excise but while I cli

  • FaceTime Airplay Mirroring on 2012 MacBook Pro

    Hi, Just wondering if anyone can help. I have a 2012 MacBook Pro and an AppleTV bought at the same time, Airplay mirroring works perfectly for music and video etc through iTunes and for Safari and Youtube etc, however I am having issues with FaceTime