SQL pure to partition the occurrences of DateTime in windows without overlap?

I have a question who, until now, I never was able to solve with a pure SQL option.

It is difficult to explain in words, but it's something like this:
given a set date and time, I would like to partition the data into windows without overlap of 30 minutes each.

the data is supposed to be partitioned in the windows of 30 minutes, which means when the data are within 30 minutes of the first, only the first occurrence is returned. in the next second after the 30th minute, the record will be considered the beginning of a new window and is also returned. If data that occurs during the latency period is deleted. the first occurrence does not necessarily occur on the 00eme minute, so the beginning of the window is never constant.


Run the query to look the dummy data below.
SELECT     'A' AS ID
          , TRUNC(SYSDATE) + 7 / 24 + 1 *(ROWNUM - 1) / 1440 AS datetime
      FROM DUAL
CONNECT BY ROWNUM <= 50
UNION ALL
SELECT     'A' AS ID
          , TRUNC(SYSDATE) + 9 / 24 + 8 / 1440 + 1 *(ROWNUM - 1) / 1440 AS datetime
      FROM DUAL
CONNECT BY ROWNUM <= 35
UNION ALL
SELECT     'B' AS ID
          , TRUNC(SYSDATE) + 7 / 24 + 5 *(ROWNUM - 1) / 1440 AS datetime
      FROM DUAL
CONNECT BY ROWNUM <= 15
This is supposed to be the output.
ID     DATETIME
A     5/19/2010 07:00:00
A     5/19/2010 07:30:00
A     5/19/2010 09:08:00
A     5/19/2010 09:38:00
B     5/19/2010 07:00:00
B     5/19/2010 07:30:00
B     5/19/2010 08:00:00
so far, I use a PL/SQL for channel registrations. but I would like to know if this goal is achievable through SQL or not.

I tried to look at analytics, width_bucket, options ntile and alll I can think, but I just can't solve this problem at all.
Advertisement

This gives the expected results. I hope that someone can improve it...

WITH T AS (
SELECT 'A' AS ID
      , TRUNC(SYSDATE) +(6.75 / 24) AS datetime
  FROM DUAL
UNION ALL
SELECT     'A' AS ID
          , TRUNC(SYSDATE) + 7 / 24 + 1 *(ROWNUM - 1) / 1440 AS datetime
      FROM DUAL
CONNECT BY ROWNUM <= 50
UNION ALL
SELECT     'A' AS ID
          , TRUNC(SYSDATE) + 9 / 24 + 8 / 1440 + 1 *(ROWNUM - 1) / 1440 AS datetime
      FROM DUAL
CONNECT BY ROWNUM <= 35
UNION ALL
SELECT     'B' AS ID
          , TRUNC(SYSDATE) + 7 / 24 + 5 *(ROWNUM - 1) / 1440 AS datetime
      FROM DUAL
CONNECT BY ROWNUM <= 15
)
SELECT ID, DATETIME
FROM (
  SELECT A.ID, A.DATETIME, A.PREVTIME, B.NEXTTIME
  FROM (
    SELECT ID, DATETIME
         , LAG(DATETIME) OVER (PARTITION BY ID ORDER BY DATETIME) AS PREVTIME
         , LAST_VALUE(DATETIME)
             OVER (PARTITION BY ID ORDER BY DATETIME
             RANGE BETWEEN CURRENT ROW
               AND NUMTODSINTERVAL(29, 'MINUTE') FOLLOWING)
           AS INTERVAL_END
    FROM T
  ) A
  ,(
    SELECT ID, DATETIME
         , LEAD(DATETIME) OVER (PARTITION BY ID ORDER BY DATETIME) AS NEXTTIME
    FROM T
  ) B
WHERE B.ID=A.ID
AND B.DATETIME=A.INTERVAL_END
)
START WITH PREVTIME IS NULL
CONNECT BY ID=PRIOR ID
      AND DATETIME=PRIOR NEXTTIME
ORDER BY ID, DATETIME
;

Kind regards
Bob

Tags: Database

Similar Questions

  • Partition the new drive and put windows on a small partition, how can I "move it".

    Hard drive crashed and had to get a new.  We partitioned the 500 Gig into 5 segments C:.5 Gig F:10 Gig G:H: I: integer 100 Gig... We used the production disks for the computer will... After a window few months started slow like a turtle, and then began there was not enough space on the drive to work. Other readers are empty or almost empty.  I am hoping there is a simple way to move everything to another drive with more space or something.  I just drag and start again, but I have programs that I also installed that I have since lost the discs too much that I don't want to lose.
    Thank you
    Zyn

    Thanks for the info... uh do often criticize people on this site? I'm just a question because I am very novice in computer technology and I trust often more educated people. But I don't like to be belittled because I thought it was one person and another don't think it's a good idea. Worried if I should keep coming back here to get help or not.

  • Do you need to partition the hard drive to install Windows Vista Home Premium?

    I try to install Vista Home Premium on a Dell XPS 420 desktop computer and want to know if the hard disk must be partitioned before that I can do?

    If I need to, how to do?

    Thank you.

    You need at least a partition on the hard drive before you install OS, using management of build-in the windows disk, but there a lot of limit, if it could not reach your goal, you could use the 3rd party freeware

  • Oracle sql for data after the first occurrence of the hyphen

    Hi, I need oracle sql get data after the first occurrence of the hyphen.

    source of the string:
    ABCD - efgh

    I just want everything after the ' - '.

    someone help me please...

    Edited by: 1001076 on 28 may 2013 18:42

    Handle: 1001076
    Status level: Beginner
    Join date: April 18, 2013
    Messages total: 12
    Total Questions: 4 (3 pending)

    I offer you my condolences; Since you rarely get your questions answered here.

  • What is the reason for the error. weblogic.application.ModuleException: java.sql.SQLException: ORA-28001: the password has expired

    Mr President

    Make me a mistake for an adf application.

    Running application ElizaSoft on IntegratedWebLogicServer...] 
    [06:38:05 PM] Web Module ViewControllerWebApp.war recognized in project ViewController.jpr
    [06:38:07 PM] ----  Deployment started.  ----
    [06:38:07 PM] Target platform is  (Weblogic 12.x).
    [06:38:10 PM] Retrieving existing application information
    [06:38:11 PM] Running dependency analysis...
    [06:38:11 PM] Deploying 2 profiles...
    [06:38:20 PM] Wrote Web Application Module to C:\Users\TANVIR\AppData\Roaming\JDeveloper\system12.2.1.0.42.151011.0031\o.j2ee\drs\ElizaSoft\ViewControllerWebApp.war
    [06:38:22 PM] Wrote Enterprise Application Module to C:\Users\TANVIR\AppData\Roaming\JDeveloper\system12.2.1.0.42.151011.0031\o.j2ee\drs\ElizaSoft
    [06:38:23 PM] Deploying 3 data source(s) to the server...
    [06:38:24 PM] Deploying Application...
    <Jan 3, 2016 6:38:35 PM PKT> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "2192494870412" for task "0" on [partition-name: DOMAIN]. Error is: "weblogic.application.ModuleException: java.sql.SQLException: ORA-28001: the password has expired
    "
    weblogic.application.ModuleException: java.sql.SQLException: ORA-28001: the password has expired
    
    
      at weblogic.jdbc.module.JDBCModule.prepare(JDBCModule.java:402)
      at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:100)
      at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:196)
      at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:191)
      at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
      Truncated. see log file for complete stacktrace
    Caused By: java.sql.SQLException: ORA-28001: the password has expired
    
    
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:466)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:391)
      at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1126)
      at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:507)
      Truncated. see log file for complete stacktrace
    > 
    <Jan 3, 2016 6:38:36 PM PKT> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application "ElizaSoft".> 
    <Jan 3, 2016 6:38:36 PM PKT> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
    weblogic.application.ModuleException: java.sql.SQLException: ORA-28001: the password has expired
    
    
      at weblogic.jdbc.module.JDBCModule.prepare(JDBCModule.java:402)
      at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:100)
      at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:196)
      at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:191)
      at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
      Truncated. see log file for complete stacktrace
    Caused By: java.sql.SQLException: ORA-28001: the password has expired
    
    
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:466)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:391)
      at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1126)
      at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:507)
      Truncated. see log file for complete stacktrace
    > 
    [06:38:36 PM] Deployment cancelled.
    [06:38:37 PM] ----  Deployment incomplete  ----.
    [06:38:37 PM] Remote deployment failed (oracle.jdevimpl.deploy.common.Jsr88RemoteDeployer)
    #### Cannot run application ElizaSoft due to error deploying to IntegratedWebLogicServer.
    [06:38:37 PM] Cancel requested
    [Application ElizaSoft stopped and undeployed from IntegratedWebLogicServer]
    
    

    But I got back to the top of the same request for the same user and password but it works and do not give the error.

    Help, please.

    Concerning

    Mr President

    I just want to remove the old conn ide and create a new ide conn and add to the application and it works

    Concerning

  • SQL query to display the sum of the values of each June and December

    Hello having problems of construction of a query to the list SQL query to display the sum of the values of each June and December each year.

    My Table;

    TABLE name: MONTH_TERM

    Fields with values:

    TERM_KEYMONTH_ACTUALMONTH_DATE
    8250001/11/2015 0:00
    8245001/12/2015 0:00
    8240501/01/2016 0:00
    8240001/02/2016 0:00
    8245001/03/2016 0:00
    8242501/04/2016 0:00
    8243501/05/2016 0:00
    8241006/01/2016 0:00
    8240901/07/2016 0:00
    8241501/08/2016 0:00
    8242009/01/2016 0:00
    8242210/01/2016 0:00
    8243611/01/2016 0:00
    8255601/12/2016 0:00
    8256801/01/2017 0:00
    8262402/01/2017 0:00

    What I would like to see in a query result:

    TERM_KEYMONTH_ACTUALMONTH_DATETotal of 6 months
    8250001/11/2015 0:00
    8245001/12/2015 0:00950
    8240501/01/2016 0:00
    8240001/02/2016 0:00
    8245001/03/2016 0:00
    8242501/04/2016 0:00
    8243501/05/2016 0:00
    8241006/01/2016 0:002525
    8240901/07/2016 0:00
    8241501/08/2016 0:00
    8242009/01/2016 0:00
    8242210/01/2016 0:00
    8243611/01/2016 0:00
    8255601/12/2016 0:002658
    8256801/01/2017 0:00
    8262402/01/2017 0:00

    ---

    Here's my query:

    Select

    "TERM_KEY,"

    "MONTH_ACTUAL,"

    to_char(MONTH_DATE,'MM/YYYY') MONTH_DATE,

    DEAL to_char (MONTH_DATE, 'MM')

    WHEN '06' THEN (SELECT SUM (MONTH_ACTUAL)

    OF MONTH_TERM

    WHERE the to_char (MONTH_DATE, 'MM') between 1 and 6

    AND term_key = 82)

    WHEN '12' THEN (SELECT SUM (MONTH_ACTUAL)

    OF MONTH_TERM

    WHERE the to_char (MONTH_DATE, 'MM') between 7 and 12

    AND term_key = 82)

    ELSE null

    END as SIX_MO_CUMM,

    of MONTH_TERM

    where term_key = 82

    It's my results:

    TERM_KEYMONTH_ACTUALMONTH_DATETotal of 6 months
    8250001/11/15 0:00
    8245001/12/15 0:003608
    8240501/01/16 0:00
    8240001/02/16 0:00
    8245001/03/16 0:00
    8242501/04/16 0:00
    8243501/05/16 0:00
    8241001/06/16 0:003717
    8240901/07/16 0:00
    8241501/08/16 0:00
    8242001/09/16 0:00
    8242210/01/16 0:00
    8243601/11/16 0:00
    8255601/12/16 0:003608
    8256801/01/17 0:00
    8262401/02/17 0:00

    Any ideas on how to fix would be great

    Select term_key,

    month_actual,

    month_date,

    case mod (to_char (month_date, 'mm'), 6)

    When 0 then sum (month_actual)

    During)

    term_key partition

    order of month_date

    between the previous month '5' interval and the current line

    )

    end '6 MONTHS in TOTAL'

    from tbl

    order of term_key,

    month_date

    /

    TERM_KEY MONTH_ACTUAL MONTH_DAT 6 MONTHS TOTAL
    ---------- ------------ --------- --------------
    82 500 NOVEMBER 1ST, 15TH
    82 450 1 DECEMBER 15 950
    82 405 1 JANUARY 16
    82 400 1 FEBRUARY 16
    82 450 1ST MARCH 16
    82 425 1ST APRIL 16
    82 435 1 MAY 16
    82 410 2525 1 JUNE 16
    82 409 1 JULY 16
    82 415 1ST AUGUST 16
    82 420 16 - SEP - 01

    TERM_KEY MONTH_ACTUAL MONTH_DAT 6 MONTHS TOTAL
    ---------- ------------ --------- --------------
    82 422 1 OCTOBER 16
    82-436 NOVEMBER 1, 16
    82 556 2658 1 DECEMBER 16
    82 568 1 JANUARY 17
    82 624 1 FEBRUARY 17

    16 selected lines.

    SQL >

    SY.

  • How to aggregate all the events which lead to the occurrence of a complex event?

    Hello

    Is it possible to aggregate all of the events that lead to the occurrence of a complex event in this complex event?

    Let's say we have six singles events
    id    amount    groupId
    1     1         1 
    2     0         2 
    3     1         1
    4     1         2
    5     2         2
    6     1         1
    The definition of complex event is
    select sum(amount), groupId from myStream[range 20 seconds slide 20 seconds] group by groupId having sum(amount) = 3
    Consider that I have the following class for my complex event:
    public class ComplexEvent {
        private int groupId;
        private int amount;
        private List<SimpleEvent> events;
    
        // getters and setters
        ...
    }
    Is it possible to have two complex events:
    ComplexEvent1 = {groupId=1, amount=3, events=[{id=1, amount=1, groupId=1}, {id=3, amount=1, groupId=1}, {id=6, amount=1, groupId=1}]}
    ComplexEvent2 = {groupId=2, amount=3, events=[{id=2, amount=0, groupId=2}, {id=4, amount=1, groupId=2}, {id=5, amount=2, groupId=2}]}
    How can achieve us?

    Hello

    I blogged an example of solution to this type of use case since it is a common scenario in the CEP applications:

    http://blogs.Oracle.com/CEP/2010/08/enriching_complex_events_with.html

    There are not currently out-of-the-box support for the events of paging to disk storage. If you really more events that can fit into the Java heap, you can try persistent events of the database or a data grid, such that the consistency and by linking to the database or the cache to create the event complex containing the events of causality.

    Another approach is to horizontally partition the flow of incoming events on multiple servers.

    Kind regards
    Seth

  • An error occurred when to partition the drive

    I have a MBP 2012 retina end 13 "El Capitan 10.11.6

    The hard drive in the machine is swapped with Transcend SSD of retinaTRIM is not enabled.

    I'm trying to install 10 Windows using Boot Camp, and I get this error.

    An error occurred when to partition the drive

    Your drive cannot be partitioned.

    I've tried-

    • reset the PRAM,
    • First aid running in the desktop utility and
    • running/sbin/fsck - AF in single user Mode.

    Nothing has worked.

    Any help is greatly appreciated.

    Maybe you have not enough contiguous free space to create the partition.

  • Uninstall the bootcamp partition: the startup disk cannot be partitioned or restored to a single partition.

    A few months ago, I created a Windows 8 bootcamp partition, and then, I updated for Windows 10 without any problem. But I no longer need and I would attribute this space to OS X. The problem is when I try to remove it from the app of Bootcamp, I get this message: "the startup disk cannot be partitioned or restored to a single partition. The startup disk must be formatted in a single volume in Mac OS extended (journaled) or already partitioned by Boot Camp Assistant to install Windows. »

    It comes to the current state of the hard drive:

    You have an idea? Thanks for the help.

    I finally solved it. It seems that I had a not mounted partition which it has not been used. I removed it and it solved all the problems:

  • delete the partition after a failed installation of windows 10

    Hello world

    How is it possible to delete partitions, if in disk utility, there is no possibility to click on the '-' key?

    So I made a failure (several) attempts to install windows 10 on my new iMAC.

    I could download an ISO of windows and start the bootcamp assistant.

    In the last attempt of last night, I selected the bootcamp in windows installation partition, however, installing windows said it was impossible to read the hard drive.

    I then re-formatted this partition (BOOTCAMP) in the installation of windows, and after that, still could not read.

    Then, I deleted the bootcamp partition in windows and re-created a partition on "unallocated space" in the windows installation.

    Installing windows 10 still wouldn't move forward then I've bailed out and went back to OS X with the hope of turning it back on (again) by deleting partitions.

    I was unable to delete the Mac partition.

    Then, I deleted this partition (the one original bootcamp) and reformatted as OS x journaled. At least now, I can see the Partition.

    However in Diskutil, I was then impossible to delete this Partition. There is also a small partition 16 MB that cannot be erased.

    Wizard bootcamp will be past a pop up station: the startup disk cannot be partitioned or restored to a single partition.

    So I will now try to delete these partitions (the boy and the training camp original one) merge into the original and give then installing bootcamp, another go when I have a lot of energy!

    any help would be appreciated. I'm a little cautious to use Terminal command lines for fear of ruining my new computer.

    concerning

    Evan

    1. your iMac has a Fusion drive?

    2. don't mix to disk utility and Wizard of BC. They can lead to a host of issues.

    3. If you do not typos in the Terminal, they provide much more rich in detail. You have a Time Machine backup, put in place?

    4 can you post the output of the following Terminal commands?

    diskutil list

    Cs diskutil list

    sudo TPG - vv - r see the/dev/disk0

    sudo fdisk/dev/disk0

    The "sudo" commands will prompt to enter your password, and there do not appear to come back. You can also see caution against improper use 'sudo' and the potential loss of data due to an "abuse" of the order.

  • How to partition the hard drive

    Hi, anyone knows how to disable partition the hard drive? Getting sick of the transfer of information between C: and E: Paulette

    Go to control panel, administrative tools, computer management, disk management.

    Do right click on E a remove it. After that, you should be able to enlarge C with right click and choose the option of not. But you'll have to save files on E first, so as not to lose them.

    If this does not work for any reason, you will still be able to use 3rd programs like partition magic. I've used several times and I am very happy with it.

  • Satellite M70 - after HARD drive partitioned, the OS does not start

    Hello

    Good then this is a real doozy, and I hope that someone will help.

    I started to fix my satellite m70 girlfriends using the disc of recovery etc, everything went fantastic, the HARD disk has been erased and Windows + all software has been reinstalled.

    Then I thought it would be a good idea to use partition magic to partition the hard drive, so I chose the main hard drive and cut 10GB of it to put in place a new partition.

    I rebooted, and then after Windows restarted again completed.

    NOW, it does not charge, it says no operating system, so I tried to start with the recovery disk and all over again...

    If I click on continue (to start the recovery process), however it is said now that the "Error #1828", free space is too small.

    I'm really angry that this has happened and I just want to start over again.

    Can someone help me with this?
    I can't access the Bios either (not sure if that might help), because I don't know the password (must be a fault im not aware of).

    Help, please.

    Thank you
    SG

    I think that this is the reason why you used a tool to change the size of the partition. At best, this should be done before you install Windows and 10 GB is a little too small for Windows. You must use at least 15-20 GB for the first partition where the BONE is placed.

    To resolve this problem, you must delete all existing partitions before using the recovery disk. Therefore, you can use a Windows XP disk or something else. Just boot from it and delete all partitions. Then the recovery disk should work.
    Check it!

  • The El Captain deleted my Windows partition and I can't get the rear space.

    Hey guys. After the upgrade to El Captain, I recently discovered that my Windows partition has been erased for some reason I don't know. I thought it was ok, that I would be re - install again, but I met some difficulties. In the tab "about this Mac" storage, there is no acknowledgement of the 60 GB drive I've used for windows and for Mac I have only 430/500 GB max, which means that the 60 GB is still a stranger in the car. I opened utility disc (image below) and as I thought there is a 60 GB named Untitled drive I can not recover when I try to partition the hard drive. Moreover, as you can see, the drive is not on the left side.

    I'm really new to technology and not great with following the complicated steps, so if someone could help me with this is a simple but effective, way that I would be more than grateful!

    El Capitan Upgrade can cause problems with Windows installed. It may still be recoverable.

    Of / run Applications-> Utilities-> Terminal, triple - click on each of the lines highlighted next, copy each line to help (command + C) and paste (command-V) in the Terminal window. After the release and after editing to remove personal information.

    The "sudo" commands will prompt to enter your password, and there do not appear to come back. You can also see caution against improper use 'sudo' and the potential loss of data due to an "abuse" of the order.

    diskutil list

    Cs diskutil list

    sudo TPG - vv - r see the/dev/disk0

    sudo fdisk/dev/disk0

  • How to partition the HARD on Satellite L300 drive?

    I'm crazy little go! I just bought a laptop L300 and I was totally reassured I was able to partition the drive. I have partitioned many readers in my life and know what I'm doing (for the most part)-, but this one - I can send it to the store.

    It has a 250 GB hard drive - main drive c, d of smaller volume and 2 hidden volumes. I have 4 other volumes (personal, music, images and desktop). I used the Vista partition utility and it won't let me (it is said that it will create dynamic disks - I want just simple additional disk volumes) and the shop recommended Disk Director

    Can someone tell me how to do this - it's a simple operation on all the other computers I bought

    Jennifer

    Hello

    If you create the own Toshiba recovery disc then you're definitely on the safe side.
    The use of the recovery disk would fix the laptop to the factory setting.
    It also means that the HARD drive would be a format too.

    The recovery disc formats the HARD whole disc first, erases all partitions, and then creates the partitions and installs the operating system with all the tools and drivers Toshiba.

    Greetings

  • How to partition the hard drive in my satellite M40X-189?

    Please can you advise the team?
    I would like to have the operating system and application programs in a partition and the data I've created in another partition.
    Please can I have advice from the team?
    Has anyone partitioned the hard drive on their satellite M40X-189 and what software did you use to do the partitioning?
    Also, I just defragged my hard drive and the card reader can be seen at: http://www.seniorvalues.org/drive%20map.jpg
    I am curious about the above provision given that free space if 52%, but white space does not reflect this and there is a piece of defragmented files and folders around the middle of the big whitespace at the end of the training I was expecting to be adjacent to the last great defragmented file.
    TIA
    Welshmike

    Hello

    I use partition magic to create and manage new partitions. In my opinion it of the best tool if you want to work with partitions.
    I have 2 partitions on my unit. C for OS and D for the 3rd of data and files. In this case if I recover my unit only the first C partition will be formatted.

    Good bye

Maybe you are looking for