Group by on date field with time difference of up to 1 minute

Hi,
I need to do a group by on a date field and some other fields, but want to include in the same group rows that are identical but may have a difference of up to a minute in the date field.
group by trunc(datefield,'MI') wouldn't work in cases like 00:00:50 and 00:01:10 (20 sec difference).
I can do a semi join with where exists and between on the date field, but am hoping for another solution.
any ideas?
thanks.
Edited by: Pyrocks on Sep 14, 2011 2:16 PM

Hi,
It sounds like you want something like this:
WITH     got_new_grp     AS
     SELECT     x.*     -- or whatever columns you need
     ,     CASE
              WHEN  datefield > MAX (datefield)
                         OVER ( ORDER BY      datefield
                                ROWS BETWEEN  UNBOUNDED PRECEDING
                                     AND          1         PRECEDING
                              ) + ( 1 / (24 * 60))
              THEN  1
          END     AS NEW_GRP
     FROM     table_x     x
--     WHERE     ...
,     got_grp          AS
     SELECT     n.*
     ,     COUNT (new_group) OVER (ORDER BY  datefield)     AS grp
     FROM     got_new_grp     n
SELECT       MIN (datefield)     AS start_datefield
,       MAX (datefield)     AS end_datefield
,       COUNT (*)          AS cnt
FROM       got_grp
GROUP BY  grp
ORDER BY  grp
;Of course, this makes assumptions for all the things you didn't explain.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
Explain, using specific examples, how you get those results from that data. Be sure to include an example like the one Kim posted, where rows a and c are more than a minute apart, but both are within a minute of row b, or are connected by a chain of rows each less than 1 minute apart from its neighbor.
Always say what version of Oracle you're using.

Similar Messages

  • How to filter a table using column filter on a date field with time?

    Hi,
    I have a date field where I am inserting a date+time value, for example: 01/01/2012 09:30:00 So, I would like to filter an adf table using a column inputdate filter to filter only by date this field.
    I was testing using formats but with no luck.
    Any Idea?
    Thanks,
    jdev 11.1.2.3
    Edited by: jhon.carrillo on Oct 29, 2012 12:23 AM

    Then, try to add another attribute in your SELECT VO statement, which truncates the original date_and_time field:
       SELECT.... TRUNC(DATE_AND_TIME) as truncated_dateAfter that, put reference to that attribute in the filter facet, as follows
             <f:facet name="filter">
                      <af:inputDate value="#{vs.filterCriteria.TruncatedDate}" id=.../>
             </facet>Do not forget to add the TruncatedDate attribute in the <tree...> binding in the pageDef, along with others VO attributes. Do that manually.

  • How to solve the problem with time difference?

    Hi,
    I work in India with time difference about 12 hours faster than American time.
    I put a validation in my application as follows:
    IF :P2_FINISH_DATE > SYSDATE THEN
    return false;
    else
    return true;
    end if;
    Today (13-Mar-09) at 9:30 am according to my system, I entered 13-Mar-09 as FINISH_DATE.
    But it returned false with an error message: "Finish date cannot be greater than system date."
    I changed my system time as 13-Mar-09, 9:30 pm. Then it accepted 13-Mar-09 as FINISH_DATE.
    How can I solve this issue.
    Would appreciate your help.
    Thanks,
    Guy

    Hi Arie,
    Thanks for the code.
    Your code works perfect in SQL Commands.
    But I don't know how to use the code in my application.
    Would appreciate if you can help me know the followings:
    - How to define two application processes -- before header and after submit (before any processing) – with the proper alter session statement.
    - How to use the APEX VPD field to do the same.
    FYI, I use the following codes:
    - For file upload
    If (:p2_SUBMIT_FILE is not null) then
    insert into PM_DOCUMENT (id, name, blob_content, mime_type, PROJECT_NAME, SUBMIT_TIME, SUBMITTED_BY)
    select id, :p2_SUBMIT_FILE, blob_content, mime_type, :P2_NAME, SYSDATE , :P2_UPDATED_BY
    from apex_application_files
    where NAME = :p2_SUBMIT_FILE;
    Delete from apex_application_files where name = :p2_SUBMIT_FILE;
    end if;
    - For Data entry validation
    IF :P2_START_DATE > :P2_FINISH_DATE
    OR :P2_START_DATE > :P2_TARGET_DATE
    OR :P2_FINISH_DATE > SYSDATE THEN
    return false;
    else
    return true;
    end if;
    Thanks,
    Guy

  • How to compare table's date field with dropdown year field

    Hi All,
    I have one requirement to display the selected rows from a database table based on the selection of drop down.
    Here, I have one dropdown of year(like 2009,2010,....) and I have one database table which contains one field with "DATE".
    Now, I want to compare table's DATE field with my dropdown field.
    Problem is that table's DATE field is of type "DATS" and dropdown is of type INTEGER(or) STRING ...
    How to compare this fields?
    Can any one please give me solution for this...!
    Thanks in Advance!

    Hi  sreelakshmi.B,
    try the following:
    DATA lt_dats        TYPE TABLE OF dats.
    DATA l_dat_i        TYPE          i.
    DATA l_dat_c_4(4)   TYPE          c.
    DATA l_dat_c_12(12) TYPE          c.
    DATA l_dats_from    TYPE          dats.
    DATA l_dats_to      TYPE          dats.
    *Move Date from Integer to Char
    l_dat_c_4 = l_dat_i = 2005.
    *Create Date From use in WHERE-Clause
    CONCATENATE '01.01.' l_dat_c_4 INTO l_dat_c_12.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
         EXPORTING
              date_external            = l_dat_c_12
         IMPORTING
              date_internal            = l_dats_from
         EXCEPTIONS
              date_external_is_invalid = 1
              OTHERS                   = 2.
    IF sy-subrc <> 0.
    ENDIF.
    *Create Date To use in WHERE-Clause
    CONCATENATE '31.12.' l_dat_c_4 INTO l_dat_c_12.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
         EXPORTING
              date_external            = l_dat_c_12
         IMPORTING
              date_internal            = l_dats_to
         EXCEPTIONS
              date_external_is_invalid = 1
              OTHERS                   = 2.
    IF sy-subrc <> 0.
    ENDIF.
    * Select records in range
    SELECT *
           FROM [DBTAB]
           INTO TABLE [ITAB]
           WHERE [DATE] BETWEEN l_dats_from
                        AND     l_dats_to.
    Regards
    REA

  • Want date displayed with time on the top banner

    Want date displayed with time on the top banner
    On the top banner, I see signal, network, wifi, time, alarm, Bluetooth and battery. I want to see date and month and year too. How?

    There isn't a way to display the date in a banner..  BUT - The calendar icon does display the date and day. 
    HTH

  • How to convert a date field with format (dd,mm,yyyy) to format (mm,dd,yyyy)

    Hello.
    How to convert a date field with format (dd,mm,yyyy) to format (mm,dd,yyyy)
    I have text field which has a databind to a date field. When I click on it, we can select the date, it is added on the format (dd,mm,yyyy). When I want to insert this date field to a database It doesnu2019t allow me to do it because it will only accept date field on the format (mm,dd,yyyy)
    I tried to store this format on a date variable and I get a message saying that is impossible to convert a string into a date.
    Regards,
    Jose

    Hi Jose,
    usually you format strings in c# like
    string.Format("{0:yyyyMMdd}", insertyourstring);
    in your case
    string.Format("{0:MM/dd/yyyy}", insertyourstring);
    [look here|http://idunno.org/archive/2004/14/01/122.aspx]
    there are more details
    if everything fails split the string with Mid()
    or ask me
    lg David

  • Data record with time interval error

    Hi,
    I have come across the following error.
    Data record with Time interval error and data is getting loaded into data target and no PSA in between.
    thanks
    kris

    Hi Kris,
    Could you please explain your problem little bit more. I mean what is source and target, or you using IP or DTP.
    goto the details in monitor tab, you will come to know to which record yo uhave error.
    If you are running IP, it is recommended to keep PSA.
    Regards,
    Venkatesh

  • Can someone help with a previous post labeled "Writing to a data file with time stamp - Help! "

    Can someone possibly help with a previous post labeled "Writing to a data file with time stamp - Help! "
    Thanks

    whats the problem?
    Aquaphire
    ---USING LABVIEW 6.1---

  • How to replace blank values in DATE field with 00000000

    Hi
    I have a DSO with Date field in which there are blank values. I want to replace the blank values in the DSO for date field with 00000000. Because of this blank values in the DSO the report is giving an ORA error.
    How do we replace the blank values in the DSO for historical data and also the new loads?
    Please advise.
    Thank you.
    Regards,
    Pavan.

    Hi Suman,
    I'm trying to run a query built on a DSO. The DSO has a field 'Start Date'. This Start Date InfoObject has a reference Char as 0DATE.
    This Start Field has blank values due to which I'm getting the ORA-01722 error. I came across many threads with same topic of discussion. As mentioned in one of the Threads I have written a program to update 'Start Date' with 00000000. The code wriiten is "UPDATE /BIC/AZ_MONINV00 SET /BIC/ZSTR_DTE = '00000000' where /BIC/ZSTR_DTE = ' '.
    Now when I see the data in the active data table of DSO the blank value is replaced with '00000000'.
    But If I right click on the DSO click on display data the 'Start Date' field is blank. And now the Query also gets executed without any error. But in the output of the query the 'Start Date' Field has "#" values.
    Can anyone suggest on how to remove these "#" values in the report?

  • Create Multiple Signature and Date fields with a custom Toolbar Button

    First off, thanks in advance!  I am a scripting newbie and I am trudging my way through with very little experience with scripting of any kind.  I am good at taking other's scripts and forming them into something I need, but I can't seem to find anything to do what I want.
    Using Adobe Acrobat X, I am trying to create a toolbar button that I can press to create multiple signature and date fields with predetermined locations.
    Below is the script I have that is working to create just a single signature box, but I can't seem to figure out the exact syntax to have that same button create multiple fields.  In total it is 9 signature fields and 9 date fields need to be created.  If you can just give me an example of what the button would look like with multiple scripts?  I was assuming I would set up multiple variables and then in the cExec property of the toolbar button I could just call out all of those variables? 
    var sigswm = "addField('sigSWM', 'signature', '0', [108, 198, 494.64, 72])"
    app.addToolButton({cName: "dotbutton", cExec: sigswm, cLabel: "Place Signature and Date Blocks",});
    Thanks in advance for any help you can provide.
    Billy Sweeney

    Thanks!  That was probably the only thing I didn't try.
    I do have one more question.  What I want is when the signature field is clicked it fills out a specific date field. I beleive the script I want would be:
    var currentTime = new Date()
        var month = currentTime.getMonth() + 1
        var day = currentTime.getDate()
        var year = currentTime.getFullYear()
        var signingTime = day +"/"+month+"/"+year
        var f = this.getField("dateSWM"); 
        f.value = signingTime;
    I found this on another thread that mentioned it could be placed in the Signed tab of the signature properties dialog.  I am assuming it would be placed in my button script file as a setAction script for each signature, but I am not real sure exactly where or how?

  • Get Date together with time

    I am having a problem to use Long, So that i can display date together with Time. What i can get now is 2002-01-23 but i want 2002-01-23 20:23:23 (yyyy,mm,dd,hh,mm,ss).
    Plase reply very urgent.

    Think of a Date/Time in an abstract way...meaning a specific point in
    time. This can be represented many ways, depending on the "Calendar"
    used as a basis, i.e. Hebrew Calendar, Chinese Calendar, Gregorian
    Calendar, etc. Java has resolved this by suppling a Calendar object
    and providing a Gregorian Calendar implementation.
    Here is how I would return the java.sql.Date object:
    java.util.Calendar c = java.util.Calendar.getInstance();
    c.set(year, month, date, hour, minute, second);
    java.util.Date d = c.getTime();
    java.sql.Date sd = new java.sql.Date(d.getTime());
    Pete

  • How do I put date along with time on my new iPad?

    I need to put date along with time on the top bar on my new I pad but just can't do it, need some help. Thank you in advance.

    Unless you can do it with a third party app - and I haven't seen one that will do it - you can't put the date at the top of the iPad. Those features are built into the iOS and there is no user setting to change or add anything to the time setting at the top.

  • Field with time in minutes and seconds

    Dear community,
    first of all, I am using Apex 3.1 on Oracle 10g, if this is necessary to know (yes I know, an old version, but given by the company I'm working for). After I've developed a few applications in Apex, thank to the forum and all the answers inside, I came to a problem that I could not solve:
    I want to have a normal text field, where the user can enter a duration of an event (e.g. "3:45" or "2:30"). That duration will allways be in the format "MM:SS". No hours, no milliseconds... But how can I save the given values in the database, so in which format? A varchar would be a possibility, but I want to build a report later on, where there is a sum of the times. And how to get a sum of varchar?! But how to make it clear to Apex and Oracle DB that the users gives in a time and not a varchar? The only thing oracle offers is a date field, but I want to save a time and not a date!
    Does anybody has a clue for me, cause it seems to me, that possibly I just don't know what I'm searching for, cause people must have had this problem before!?
    THanks for your help!
    Regards
    hoge

    But how to make it clear to Apex and Oracle DB that the users gives in a time and not a varchar? The only thing oracle offers is a date field, but I want to save a time and not a date!All APEX items are character strings, so implicit or explicit conversion is required when the values are stored in database columns. For the recommended <tt>INTERVAL DAY TO SECOND</tt> columns, use <tt>TO_DSINTERVAL</tt> to perform the conversion.
    Use <tt>EXTRACT</tt> to get the minute and second values from the <tt>INTERVAL</tt> going in the other direction.
    but I want to build a report later on, where there is a sum of the times.A user-defined aggregate function can be created to sum <tt>INTERVAL DAY TO SECOND</tt> values: here's an example.
    APEX's lack of built-in support for summaries on <tt>INTERVAL</tt> types can be worked round by including the sum in the report query using a </tt>UNION</tt>:
    SQL&gt; with test_data as (
      2      select
      3                rownum n
      4              , numtodsinterval(ceil(dbms_random.value(0, 3600)), 'SECOND') t
      5      from
      6                dual
      7      connect
      8                by rownum &lt;= 10)
      9  select
    10            n
    11          , t
    12          ,    to_char(extract(minute from t))
    13            || ':'
    14            || to_char(extract(second from t), 'fm00') t1
    15  from
    16            test_data
    17  union all
    18  select
    19            null
    20          , sum_dsinterval(t)
    21          ,    to_char(extract(hour from sum_dsinterval(t)))
    22            || ':'
    23            || to_char(extract(minute from sum_dsinterval(t)), 'fm00')
    24            || ':'
    25            || to_char(extract(second from sum_dsinterval(t)), 'fm00')
    26  from
    27            test_data
    28  order by
    29            1 nulls last
    30  /
             N T                              T1
             1 +000000000 00:04:46.000000000  4:46
             2 +000000000 00:07:05.000000000  7:05
             3 +000000000 00:31:11.000000000  31:11
             4 +000000000 00:53:16.000000000  53:16
             5 +000000000 00:19:02.000000000  19:02
             6 +000000000 00:57:12.000000000  57:12
             7 +000000000 00:43:29.000000000  43:29
             8 +000000000 00:03:11.000000000  3:11
             9 +000000000 00:16:40.000000000  16:40
            10 +000000000 00:20:49.000000000  20:49
               +000000000 04:16:41.000000000  4:16:41A custom named column (row) report template with conditional templates can be used to layout and format such a report so that the summary row(s) are properly handled.

  • Querying a date field with different masks in form and database

    Dear friends,
    I have a field with date format mask dd/mm/yyyy hh24:mi:ss, but the same field has date format dd/mm/yyyy inside the form which queries it.
    If I run this form, obviously I will query this date in dd/mm/yyyy format mask, but this date is not being found because it doesn't include hh24:mi:ss (hour) from the database field.
    How can I solve this problem? I tried to change my form, putting a format mask with hours, but it requires me to query this date with time, and obviously no one needs to know the exact moment (with seconds!) when the date was recorded in the database.
    Thanks, and best regards,
    Franklin

    Franklin,
    You could instruct your users to use the '%' when they enter a date search criteria. Another alternative would be to programatically add the '%' to the date. Also, if your Block based on a view you could alter the vuew to use TRUNC() on the date field to drop the time.
    Another option would be to use the Pre-Query trigger to modify the Block WHERE clause to: TRUNC(date_field) = :block.date_field.
    Hope this helps.
    Craig...
    -- If my response or the response of another is helpful or answers your question, please mark the response accordingly. Thanks!

  • Update Date field with mm/dd/yyyy format

    I have a Field with Date Type then I have to update it with sysdate but only with the mm/dd/yyyy (not TIME)
    I make:
    UPDATE TABLE
    SET DATE_FIELD = to_date(to_char(sysdate, 'mm/dd/yyyy'),'mm/dd/yyyy')
    Is There a better way to do it?????
    Thanks!

    You can use
    trunc(sysdate)
    for the insert.
    Regards,
    Gerd

Maybe you are looking for

  • At selection screen output problem when a field is obligatory

    Hi All, I have two radiobuttons on the selection screen and when I select first radiobutton one screen should display and the other should not be displayed and vice-versa. It is working fine if I do not have a mandatory field.I am pasting my code her

  • How do I disconnect sync from ipod to ipad

    I have an ipad that is primary device, and have an ipod that just purchased & set up icloud and syncd with w/ my ipad. I want to disconnect my ipod from the information being sent to my ipad accounts. How?? thanks!

  • Rendering / Exporting Animation for FLASH

    Hello Friends, Some time ago I made an animation in After Effects CS3 and either Rendered it or Exported it as an SWF. I then Imported it into my Library in my FLASH CS3 movie and all was terrific. Although I have spent the last four days going throu

  • Data transfer from iTouch to an external HD

    If you caught the lenghthy post from joblo22, then you know I have a dying HD in my iBook. I have an iTunes library that I built in the previous years - much bought from iTunes and therefore the only copy of this music. My iTouch has about 2/3's of m

  • The limitation of Web Services ???

    Hi All, I am currently developing an application using two servers. I want ServerA to get the request from client and then I will use Web Services to pass the entired "HttpRequest" as parameter to ServerB. I am curious that if it's possible to implem