How to sort time consecutive groups

Hi all

I use Oracle 10 on Windows 2003. I have the following table example
create table test (t_date,t_name,t_value) as
select to_date('2010-01-01:13:45','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '20' t_value from dual union all
select to_date('2010-01-01:13:46','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '30' t_value from dual union all
select to_date('2010-01-01:13:47','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '40' t_value from dual union all
select to_date('2010-01-01:13:48','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '30' t_value from dual union all
select to_date('2010-01-01:13:49','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '30' t_value from dual union all
select to_date('2010-01-01:13:50','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '30' t_value from dual union all
select to_date('2010-01-01:13:51','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '30' t_value from dual union all
select to_date('2010-01-01:12:45','YYYY-MM-DD:HH24:MI') t_date, 't2' t_name, '20' t_value from dual union all
select to_date('2010-01-01:12:46','YYYY-MM-DD:HH24:MI') t_date, 't2' t_name, '30' t_value from dual union all
select to_date('2010-01-01:12:47','YYYY-MM-DD:HH24:MI') t_date, 't2' t_name, '40' t_value from dual union all
select to_date('2010-01-01:12:48','YYYY-MM-DD:HH24:MI') t_date, 't2' t_name, '30' t_value from dual union all
select to_date('2010-01-01:12:49','YYYY-MM-DD:HH24:MI') t_date, 't2' t_name, '23' t_value from dual union all
select to_date('2010-01-01:12:50','YYYY-MM-DD:HH24:MI') t_date, 't2' t_name, '33' t_value from dual union all
select to_date('2010-01-01:12:51','YYYY-MM-DD:HH24:MI') t_date, 't2' t_name, '35' t_value from dual union all
select to_date('2010-01-01:12:45','YYYY-MM-DD:HH24:MI') t_date, 't3' t_name, '20' t_value from dual union all
select to_date('2010-01-01:12:46','YYYY-MM-DD:HH24:MI') t_date, 't3' t_name, '30' t_value from dual union all
select to_date('2010-01-01:12:47','YYYY-MM-DD:HH24:MI') t_date, 't3' t_name, '40' t_value from dual union all
select to_date('2010-01-01:12:48','YYYY-MM-DD:HH24:MI') t_date, 't3' t_name, '30' t_value from dual union all
select to_date('2010-01-01:12:49','YYYY-MM-DD:HH24:MI') t_date, 't3' t_name, '23' t_value from dual union all
select to_date('2010-01-01:12:50','YYYY-MM-DD:HH24:MI') t_date, 't3' t_name, '33' t_value from dual union all
select to_date('2010-01-01:12:51','YYYY-MM-DD:HH24:MI') t_date, 't3' t_name, '35' t_value from dual union all
select to_date('2010-01-02:13:45','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '20' t_value from dual union all
select to_date('2010-01-02:13:46','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '30' t_value from dual union all
select to_date('2010-01-02:13:47','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '40' t_value from dual union all
select to_date('2010-01-02:13:48','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '30' t_value from dual union all
select to_date('2010-01-02:13:49','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '30' t_value from dual union all
select to_date('2010-01-02:13:50','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '30' t_value from dual union all
select to_date('2010-01-02:13:51','YYYY-MM-DD:HH24:MI') t_date, 't1' t_name, '30' t_value from dual;
I would like to create a query that will give the following results
t_name      start_t                        end_t                         start_value     end_value 
t1     2010-01-01 13:45     2010-01-01 13:51          20                30
t1     2010-01-02 13:45     2010-01-02 13:51          20                30
t2     2010-01-01 12:45     2010-01-01 12:51          20                35
t3     2010-01-01 12:45     2010-01-01 12:51          20                35
so I tried to create a query based on what I read in the forums (method Tabibitosan by Aketi Jyuuzou tutorial I wanted to get the start_t and the end_t first of all, just because I'm not familiar with this, so it's the request I created first. I did add the start_value and the end_value when I got this job
select t_name, to_char(min(t_date),'YYYY-MM-DD HH24:MI') start_t,to_char(max(t_date),'YYYY-MM-DD HH24:MI') end_t
from(select t_date,t_name,
      dense_rank() over(order by t_date)
      -Row_Number() over(partition by t_name order by t_date)
      as distance
      from test)
group by t_name,distance
order by t_name,min(t_date)
but my result is
t1     2010-01-01 13:45     2010-01-02 13:51
t2     2010-01-01 12:45     2010-01-01 12:51
t3     2010-01-01 12:45     2010-01-01 12:51
So I wonder what Miss me in my request to give the results that I need? Any help would be appreciated.

See you soon

This will help:

SQL> select distinct
  2         first_value(t_date) over (partition by t_name, trunc(t_date)) as first_date
  3        ,first_value(t_value) over (partition by t_name, trunc(t_date)) as first_value
  4        ,last_value(t_date) over (partition by t_name, trunc(t_date)) as last_date
  5        ,last_value(t_value) over (partition by t_name, trunc(t_date)) as last_value
  6        ,last_value(t_name) over (partition by t_name, trunc(t_date)) as t_name
  7  from test
  8  /
01/01/2010 13:45:00 20 01/01/2010 13:51:00 30 t1
01/01/2010 12:46:00 30 01/01/2010 12:45:00 20 t2
01/01/2010 12:50:00 33 01/01/2010 12:51:00 35 t3
02/01/2010 13:50:00 30 02/01/2010 13:45:00 20 t1

Add in the order by!

Tags: Database

Similar Questions

  • How to compare consecutive groups of numbers in tables

    Hello

    I need from there to place a table 1 d of the solution.

    I need to compare two tables and record the same numbers that are in the two tables, but also save groups of numbers which can be in one of the two compared tables.

    In the example l could not put all consecutive numbers 8,9,10,11,12 groups in a 1 d array.

    Example l have to filter the zeros and the number four.

    The numbers in the two tables are always in descending order however may not be in the order of the array index number. It's 15 = 15 index number

    A series of consecutive numbers in this example is a group which increase by a value of 1. For example. 8,9,0,22,23,24 are two consecutive groups of numbers.

    Thank you


  • How to sort, group, this xdoxslt of use?

    Dear all,

    I have the group by month:

    <? for-each-group@section:EeventsParentEvent; (xdoxslt:get_month (xdoxslt:format_date(StartDate,'yyyy-mm-dd','mm/dd/yyyy',$_XDOLOCALE,$_XDOTIMEZONE), $_XDOLOCALE))? >

    per week:

    <? for each group: (current-group); (xdoxslt:ora_format_date (xdoxslt:format_date(EventVenueStartDate,'yyyy-mm-dde)
    ((("mm/dd/yyyy", $_XDOLOCALE, $_XDOTIMEZONE), 'W'))? >

    then tried to sort because the Group has yet to sort

    <? sorting: current-group; (xdoxslt:ora_format_date (xdoxslt:format_date(EventVenueStartDate,'yyyy-mm-dd','mm/dd/yyyye)
    ((($_XDOLOCALE, $_XDOTIMEZONE), 'W')), 'Crescent', data of type = "text"? > error-> see the

    My syntax is wrong?
    because I didn't know which formula you want to use

    appreciate any help

    Concerning

    Cecilia

    I find not all wrong in this sort code.
    To sort on the week, you can use type number, although it works as a text too (in this case)

  • Anyone know how to sort the files in windows 7.

    Anyone know how to sort the files in windows 7. All of a sudden my file says "a long..., there is this month...» Last week... today. I can't deal with all the files in the folder now. How can I keep rid of one a long time ago..., this month... Last week... today) so that I can fix the whole folder?

    Hello

    Right-click on an empty area of the concerned window, select Group By, and then select None.

    Best wishes

    DP - K

  • Sort of a group of numbers

    Hi all

    I am reorganizing my digital signals by the presence of a front panel control that allows the user dynamically set the channel.

    On the front panel, I have composed a set of unsigned integer typedef.  I want to sort this cluster in numbers and be able to exploit the case of the label.

    I understand how to assemble digital waveforms with digital subset and add digital signals, but I do not know how to sort the data structure I created.

    I do not know there is an easy way to do this and she escapes just me.  I'm on the right track with my data structure?

    You can use a Cluster for the Array function to get an array of the values cluster.

    You can create a table 1 d of channels where you hardcode the labels.  (There should be ways to get programmatically the labels in a script, but I don't think it's worth the effort).

    If you bundle up your array of numbers with your array of strings so that you have an array of clusters (each element of the array is a grouping of the value and the string), you can then sort the table 1 d.

    Even simpler.  It is not necessary to get the names of the elements of script.  I've added an example VI.

  • How to sort the files transferred to the computer

    * Original title: file transfer

    I have files that have names dates in them viz ' 1986 April 1986 may "etc and I have 3000 on my computer in order of date name but when I copy the file to transfer files on an another compluter resort themselves to Aprils all together can all June etc.  Is there a way I can copy the files, but keep them in the same order?

    Hi Anthony,.

    I will definitely help you with this.

    I suggest you to refer to the advice given by Divya R 19 January 2011 and check if it helps.

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-files/how-to-sorting-and-grouping-files-in-Windows/2f2e08c0-587c-47b1-94a1-1779a91090f7

    If the problem persists or you have any other questions, do not hesitate to let us know. It is our pleasure to be of service.

    Thank you.

  • How do you time differences in first 10 items?

    Hi, I was wondering how to make time differences in first 10 elements. I tried just clidking a picture then clicking on time warp and setting the time for 1 frame but I can't apply it to all of them. I also went to Edition, preferences, general and set of stills duration by default of 1 frame, but it doesn't matter.

    Any suggestions?

    Thank you

    I did a lot of videos broken down into first.

    There are several factors that probably need to test first. The largest exam is the interval of the stills shot, and then the 'look' that one wishes to achieve.

    For the most part, I'm going to Edit > preferences (before I import still Images) and change the time again to something around 3-5 frames. This is once again, after a few tests. Then I import still Images. I also put the duration of Transitions to be quite short, depending on how many images I have chosen.

    After importing, I ensure that the fixed image files are sorted numerically, select several files and drag those to the timeline. Then, I apply the default value (shortened to change preferences > General > video Transitions) to each Image.

    Usually, I start with maybe 10 Images and experiment with life still picture, until I'm comfortable with the look for this topic.

    Good luck and hope that helps.

    Hunt

  • How to share the record group between 2 forms

    Hi all

    Some might guide me how to send one record group to another form and how it is received

    programmaticaly

    any help or advice, that I enjoyed

    Thank you

    Hello
    Little late but was not on the development computer.
    In fact the data you are trying to recover also ensure the data type. I mean if you retrieve DIGITAL data record group for the first column you use fld_1 , you must have to use the built-in GET_GROUP_NUMBER_CELL . Like this..

    DECLARE
      rg_id recordgroup;
    BEGIN
      rg_id := FIND_GROUP('my_rg');
      IF NOT id_null(rg_id) THEN
       :ctrl.text_item8 := GET_GROUP_NUMBER_CELL('my_rg.fld_1', 1);
      END IF;
    END;
    

    If If the field you get the record group's CHARACTER then you must use the built-in function GET_GROUP_CHAR_CELL like that...

    DECLARE
      rg_id recordgroup;
    BEGIN
      rg_id := FIND_GROUP('my_rg');
      IF NOT id_null(rg_id) THEN
        :ctrl.text_item8 := GET_GROUP_CHAR_CELL('my_rg.fld_1', 1);
      END IF;
    END;
    

    And if the salvage value of DATE data type, then GET_GROUP_DATE_CELL like this...

    DECLARE
      rg_id recordgroup;
    BEGIN
      rg_id := FIND_GROUP('my_rg');
      IF NOT id_null(rg_id) THEN
        :ctrl.text_item8 := GET_GROUP_DATE_CELL('my_rg.fld_1', 1);
      END IF;
    END;
    

    So, in you case I think the department_id data type is numeric in the database, and you use GET_GROUP_CHAR_CELL which will not work. Use the first one I showed you for numeric values.

    And also use the trigger a TIME NEW FORM INSTANCE used to retrieve the value. I want to use the first example in this trigger. Then you can see the value of the result of the shared record group.

    -Clément

  • How can I create a group through Outlook without the application Outlook email?

    How can I create a group by using Outlook without an application Outlook email?

    Sigmalambda wrote:

    How can I create a group by using Outlook without an application Outlook email?

    It is difficult to understand what you're trying to do. You can create a group and send an email to the group in any mail client. The recipients can use any e-mail provider or an e-mail client to receive e-mail. Please explain in more detail what you are trying to accomplish.

  • How you sort the list of the next iOS 10?

    I can't know how to sort the list by following in-app music on my iPhone 6 s.  In iOS 9, he had a handle on the right side next to the title of the song that you can tap and drag up/down to change the order of the playlist.  The handle does not appear in the App on iOS 10 music.

    So I guess you can't have activated repeat function.  Once it is off, the handles appear and you can sort your list of songs until the next.

  • How can I create a group in my address book?

    I am looking at the help page, and he has "contacts" in the list, but no link to something useful.

    How can I create a group? I want to send something to a group of people, but I don't want them to see all the other people who are part of the group.

    _ http://KB.mozillazine.org/Thunderbird: _FAQs_:_Create_Mailing_List

  • How can I send a group of addresses of recipients to someone else?

    I regularly send messages to groups of recipients (5 to 50 in size). Someone supports a part of my work; How can I send a group of addresses without having to type all of them again?
    I tried watching a group of addresses in "address", highlighting its content and by pressing Ctrl-C; but by pressing Ctrl-V in the body of an email to him does not.

    You can export books complete addresses or mailing lists.

    If these groups are already in you mailing lists the address book opens the address book and click on the folder in the list to highlight. Then go to Tools-Export.

    Then name the file, choose where to save it and decide what file format can use the new person.

    The LDIF format is best if they are a user of Thunderbird. Separated by commas works with most, and can be opened in Excel to view or change.

    And then send the file.

    Export your address book is a good way to save problems later.

  • How can I make a group of tiles is one fell swoop

    How can I make a group of tiles is one fell swoop? Thank you very much for your help!

    Please explain what you want to do - when you import photos into iPhoto, the thumbnails are generated automatically - youo need not to do something

    and verisy you use OS X 10.6.8 as you say it and tell us what version of iPhoto you use

    LN

  • My ipod video 5th generation won't play of smart playlists in order with 12.4 itunes, itunes can not remember how to sort things either. When you going to solve the problem?

    My iPod video 5th generation won't play of smart playlists in order with 12.4 iTunes, iTunes can not remember how to sort things either.

    When you going to solve the problem?

    Can I do to solve this problem?

    Use the view of songs to set the order you want. Right-click on the name of the playlist in the left sidebar, and then select copy to Play Order in the context menu. Sort the list on the left most column of numbers, or use view > sort by > order of Playlist. Device synchronization.

    TT2

  • How can I change the group that is assigned to a contact?

    I synchronize contacts on my 2 iPhones, 2 iPads, MacBook Pro and iMac. I would like to change some of my current designations of the group for some of my contacts. How can I change the group that is assigned to a contact?

    Mark,

    First of all, make sure that you deal with iCloud contacts.

    With the help of your MacBook Pro or iMac Contacts open and remove unwanted contacts outside the group. You will be asked "do you want to remove the card for 'XXX' or delete Group 'YYY'.» Choose "remove group.»

    Then go to "All Contacts" and drag the name of the new group.

    If you want to see what the contact belongs to groups, click on the contact and press 'option '. All groups with this name will be highlighted.

Maybe you are looking for

  • How do I restore my laptop to factory settings?

    Toshiba how to restore factory settings (by pressing 0 on boot dosnt work)? Hi guys How can I restore my Toshiba L650 to factory settings? I haven't tried the 0 to start any work that I have installed a new version of w7 (from home premium to profess

  • Why my PC does not restart during the installation of XP?

    I want to install XP on my desktop and its all good and restarts after having pre installed (when windows copies the files), then the windows loading logo shows, then it starts to install with the control points on the right as follows: @ collecting

  • Windows Boot Manager failed error

    NB: I have a very short time. her tomorrow. I have a very glitchy w4 Iconia, who has been with us for a day and night, with several screen flickers and this problem I am submitting. Boot Manager Windows failed to start my iconia, which means I can't

  • I need assistance with Outlook Express

    I need assistance with my outlook express. Please

  • Thinner replacement battery for HP Pavilion dv6

    I have a Pavlillion HP dv6-1350US Entertainment PC.  It has great battery 12 cells that creates a bump, sometimes embarrassing (especially for the trip) on the bottom. Is there a smaller battery that can replace this battery?  The one that does not a