Date Grouping by specific interval

Hi all,
I have a case where i need to build a query to count the dates and then group them by a specific interval, I mean the user may select a date range 1 year but group the result by 7 days, so the query must return counts of dates for every 7 days.
lets have the following table : (the real database store the date as long (date in milliseconds))
Date | SevEnum
1-Feb-2010 00:00:00 | 1
1-Feb-2010 15:00:00 | 1
2-Feb-2010 12:00:00 | 1
2-Feb-2010 14:00:00 | 1
3-Feb-2010 00:00:00 | 1
3-Feb-2010 06:00:00 | 1
The user can enter any interval he want, examples:
grouping by *1 year*
result must by :
Date | Count
2010 | 6
grouing by *1 day*
Date | Count
1-Feb-2010 | 2
2-Feb-2010 | 2
3-Feb-2010 | 2
grouing by *2 days*
Date | Count
1-Feb-2010 | 4
3-Feb-2010 | 2
the User can group the date by any time Unit (seconds, minutes, hours,days, week,months,years)
I can't using TRUNC() because, its just for specific unit (ex. just 1 day, not 2 days).
Is there any idea or logic to be general as possible, please advice.
thanks,
Edited by: user9183438 on Mar 9, 2010 3:20 AM
Edited by: user9183438 on Mar 9, 2010 3:21 AM

You can use TRUNC to truncate by day, month, hour, etc:
SQL> SELECT TRUNC(sysdate, 'mm')
  2  FROM   dual;
TRUNC(SYSDATE,'M
01/03/2010 00:00As for the other requirement - do the users really need to be able to group by "2 days"? Is it meaningful?
If so, then here's a method of doing what you're after (I've included various truncates just to give an idea of how the data may differ):
with dates as (select trunc(sysdate, 'mm') -10 + level dt
               from   dual
               connect by level <= 40)
select dt,
       trunc(dt, 'mm') by_month,
       trunc(dt, 'iw') by_week,
       trunc(dt, 'yyyy') by_year,
       trunc(dt, 'dd') by_day,
       trunc(dt, 'yyyy') + trunc(to_char(dt, 'ddd')/2)*2 by_2_days,
       trunc(dt, 'yyyy') + trunc(to_char(dt, 'ddd')/14)*14 by_14_days,
       trunc(dt, 'iyyy') + trunc(to_char(dt, 'iw')/2)*2*7 by_fortnight
from   dates;
DT         BY_MONTH   BY_WEEK    BY_YEAR    BY_DAY     BY_2_DAYS  BY_14_DAYS BY_FORTNIGHT
20/02/2010 01/02/2010 15/02/2010 01/01/2010 20/02/2010 20/02/2010 12/02/2010 15/02/2010 
21/02/2010 01/02/2010 15/02/2010 01/01/2010 21/02/2010 22/02/2010 12/02/2010 15/02/2010 
22/02/2010 01/02/2010 22/02/2010 01/01/2010 22/02/2010 22/02/2010 12/02/2010 01/03/2010 
23/02/2010 01/02/2010 22/02/2010 01/01/2010 23/02/2010 24/02/2010 12/02/2010 01/03/2010 
24/02/2010 01/02/2010 22/02/2010 01/01/2010 24/02/2010 24/02/2010 12/02/2010 01/03/2010 
25/02/2010 01/02/2010 22/02/2010 01/01/2010 25/02/2010 26/02/2010 26/02/2010 01/03/2010 
26/02/2010 01/02/2010 22/02/2010 01/01/2010 26/02/2010 26/02/2010 26/02/2010 01/03/2010 
27/02/2010 01/02/2010 22/02/2010 01/01/2010 27/02/2010 28/02/2010 26/02/2010 01/03/2010 
28/02/2010 01/02/2010 22/02/2010 01/01/2010 28/02/2010 28/02/2010 26/02/2010 01/03/2010 
01/03/2010 01/03/2010 01/03/2010 01/01/2010 01/03/2010 02/03/2010 26/02/2010 01/03/2010 
02/03/2010 01/03/2010 01/03/2010 01/01/2010 02/03/2010 02/03/2010 26/02/2010 01/03/2010 
03/03/2010 01/03/2010 01/03/2010 01/01/2010 03/03/2010 04/03/2010 26/02/2010 01/03/2010 
04/03/2010 01/03/2010 01/03/2010 01/01/2010 04/03/2010 04/03/2010 26/02/2010 01/03/2010 
05/03/2010 01/03/2010 01/03/2010 01/01/2010 05/03/2010 06/03/2010 26/02/2010 01/03/2010 
06/03/2010 01/03/2010 01/03/2010 01/01/2010 06/03/2010 06/03/2010 26/02/2010 01/03/2010 
07/03/2010 01/03/2010 01/03/2010 01/01/2010 07/03/2010 08/03/2010 26/02/2010 01/03/2010 
08/03/2010 01/03/2010 08/03/2010 01/01/2010 08/03/2010 08/03/2010 26/02/2010 15/03/2010 
09/03/2010 01/03/2010 08/03/2010 01/01/2010 09/03/2010 10/03/2010 26/02/2010 15/03/2010 
10/03/2010 01/03/2010 08/03/2010 01/01/2010 10/03/2010 10/03/2010 26/02/2010 15/03/2010 
11/03/2010 01/03/2010 08/03/2010 01/01/2010 11/03/2010 12/03/2010 12/03/2010 15/03/2010 
12/03/2010 01/03/2010 08/03/2010 01/01/2010 12/03/2010 12/03/2010 12/03/2010 15/03/2010 
13/03/2010 01/03/2010 08/03/2010 01/01/2010 13/03/2010 14/03/2010 12/03/2010 15/03/2010 
14/03/2010 01/03/2010 08/03/2010 01/01/2010 14/03/2010 14/03/2010 12/03/2010 15/03/2010 
15/03/2010 01/03/2010 15/03/2010 01/01/2010 15/03/2010 16/03/2010 12/03/2010 15/03/2010 
16/03/2010 01/03/2010 15/03/2010 01/01/2010 16/03/2010 16/03/2010 12/03/2010 15/03/2010 
17/03/2010 01/03/2010 15/03/2010 01/01/2010 17/03/2010 18/03/2010 12/03/2010 15/03/2010 
18/03/2010 01/03/2010 15/03/2010 01/01/2010 18/03/2010 18/03/2010 12/03/2010 15/03/2010 
19/03/2010 01/03/2010 15/03/2010 01/01/2010 19/03/2010 20/03/2010 12/03/2010 15/03/2010 
20/03/2010 01/03/2010 15/03/2010 01/01/2010 20/03/2010 20/03/2010 12/03/2010 15/03/2010 
21/03/2010 01/03/2010 15/03/2010 01/01/2010 21/03/2010 22/03/2010 12/03/2010 15/03/2010 
22/03/2010 01/03/2010 22/03/2010 01/01/2010 22/03/2010 22/03/2010 12/03/2010 29/03/2010 
23/03/2010 01/03/2010 22/03/2010 01/01/2010 23/03/2010 24/03/2010 12/03/2010 29/03/2010 
24/03/2010 01/03/2010 22/03/2010 01/01/2010 24/03/2010 24/03/2010 12/03/2010 29/03/2010 
25/03/2010 01/03/2010 22/03/2010 01/01/2010 25/03/2010 26/03/2010 26/03/2010 29/03/2010 
26/03/2010 01/03/2010 22/03/2010 01/01/2010 26/03/2010 26/03/2010 26/03/2010 29/03/2010 
27/03/2010 01/03/2010 22/03/2010 01/01/2010 27/03/2010 28/03/2010 26/03/2010 29/03/2010 
28/03/2010 01/03/2010 22/03/2010 01/01/2010 28/03/2010 28/03/2010 26/03/2010 29/03/2010 
29/03/2010 01/03/2010 29/03/2010 01/01/2010 29/03/2010 30/03/2010 26/03/2010 29/03/2010 
30/03/2010 01/03/2010 29/03/2010 01/01/2010 30/03/2010 30/03/2010 26/03/2010 29/03/2010 
31/03/2010 01/03/2010 29/03/2010 01/01/2010 31/03/2010 01/04/2010 26/03/2010 29/03/2010  You may find that you'll have to add or subtract onto the to_char(dt, 'ddd') values in order to make them us the same "start point" - eg. look at the difference for fortnight vs 14 days. Anyway, that should give you an idea of how you could do things.

Similar Messages

  • How to log waveform chart data in any file at specific interval

     i am using labview 7.0. i want to save waveform chart data in the file at specific interval given by user. Please give me solution for that.
    falgandha

    Open the example finder (Help>>Find Examples) and look at the Write Datalog File example. You can also convert your data to text to save a simple text file. Also, the tutorials in the following links probably cover something similar.
    To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here, here, here, here and here are a few you can start with and here are some tutorial videos. You can also contact your local NI office and join one of their courses.
    In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).
    Try to take over the world!

  • Group by time interval

    Hi all,
    I'd like to group data by some time interval (lets say half hour), so i can't use: group by trunc(date,?) because i don't have a time format which can describe this level of group (unless oracle has upgraded this ability...maybe a feature request:)
    is there a workaround to do that? any solution will be appreciated
    Regards
    Liron

    Hi I don't know if this would be the most optimum approach but it got the job done for me.
    I my case I had timestamps intead of date and I did the following.
    Select (CASE
    WHEN (cast(to_char(thetime, 'mi') as int) <= 30 ) THEN
    (to_char(thetime, 'hh:') || '00' || to_char(thetime, ' PM') || ' - ' || to_char(thetime, 'hh:') || '30' || to_char(thetime, ' PM'))
    ELSE
    (to_char(thetime, 'hh:') || '30' || ' ' || to_char(thetime, ' PM') || ' - ' || to_char(thetime + interval '1' hour, 'hh:') || '00' || to_char(thetime, ' PM'))
    END) ServiceTime, count(*) ServicedPeople
    From
    select (systimestamp + interval '15' minute) thetime from dual
    UNION
    select (systimestamp + interval '30' minute) thetime from dual
    UNION
    select (systimestamp + interval '45' minute) thetime from dual
    UNION
    select (systimestamp + interval '60' minute) thetime from dual
    UNION
    select (systimestamp + interval '75' minute) thetime from dual
    UNION
    select (systimestamp + interval '90' minute) thetime from dual
    group by (CASE
    WHEN (cast(to_char(thetime, 'mi') as int) <= 30 ) THEN
    (to_char(thetime, 'hh:') || '00' || to_char(thetime, ' PM') || ' - ' || to_char(thetime, 'hh:') || '30' || to_char(thetime, ' PM'))
    ELSE
    (to_char(thetime, 'hh:') || '30' || ' ' || to_char(thetime, ' PM') || ' - ' || to_char(thetime + interval '1' hour, 'hh:') || '00' || to_char(thetime, ' PM'))
    END)

  • How to query the status of disk groups in specific time?

    Dears,
    While trying connect to database , i faced ORA-00257:archiver error. Connect internal only, until freed.
    Also found in alert file ORA-15041: diskgroup space exhausted
    And found in ASM alert file WARNING: allocation failure on disk DG_DATA_0002 for file 357 xnum 2147483648
    I expected from above errors that the problem in ASM Disk groups or in file system space.
    After checking, found every thing is fine and OK as i have much free space.
    And when i tried after some time to connect to database, it connected successfully without errors.
    It means that the problem not in space,may be the status of disk groups became invalid for some time
    Appreciate your advise. And how can i know the status of disk groups in specific time?
    Thanks & Regards,,

    Hi All,
    We got another idea to create new template and use it as "Current Default Workbook".
    Then it is showing latest date as we changed one of the Text element from "Display Status of Data" to "Display status of Data To".
    But the this change is showing to my user id only but not to the other users.
    We are selecting the tick mark for "Global Default Workbook", but this tick mark is going away after each refresh. I think if this tick mark is holds permanently, my problem will solve.
    Please suggest me if you have any ideas to resolve this issue....

  • Use Date Group (Month) in a Results Filter

    Hyperion IR v 9
    I want to filter my results set by the Month Date Group.  I want Displayed in the column filter Jan, Feb, Mar....and so on.  However, when I drag that field to the filter and ask to "show values" it shows my actual dates, not the three character month value.  This monthly filter is essential for what I'm doing.  I tried creating a computed column off the month date group and set the datatype to text. All that did was retain the original date value again.  Is there a way around this?
    How can I do this?

    I've said it before in these forums:  To the maximum extent possible, avoid the built-in functions in computed items in Results.
    I've contacted Oracle about your specific deficiency (Month(column_name) returning a date rather than a month).  They say it's working as designed -- something about sorting properly.
    Use JavaScript.  Here's a definition for your computed item:
    ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][date_column.getMonth()]

  • AP Payment User Responsbility's Data Group to be assigned for application as Payables or Payments?

    Hi,
    I am in version R12.1.3 . I have a requirement to create a user who must have access only to create payments in AP module.So when i try to define a responsibility for this payment user
    there is a data group to be assigned. In this data group block for application there are 2 options i.e Payables & Payments? What should I select & what is the difference of selection one over the other?
    Appreciate your help.
    Thanks

    Hi,
    i did not see any difference .... I performed a test case, where i created a payment using the new responsibility i have created having data group application as Payments, the payment was successful ... Later i have modified the data group for this new responsibility from payments to payables, then the test payment i have made was also successful....
    Not sure about its impact, may be i am having responsibilities which has full access, hence i cannot see the difference in my environment ....
    Regards,
    Ivruksha

  • How can I find what scom group a specific server belongs to using powershell?

    Environment:  SCOM 2007 r2
    Server in question:  Running Windows 2003 Std. (yes I know this sounds crazy)
    Why do I need this:  I noticed at the console level we have had server unexpected shutdown events which are not generating email notifications. 
    Source shows: Windows 2003 Server Standard Edition
    Alert Rule:  Windows Shutdown Unexpectedly
    From what I see these are all windows 2003 server Std edition systems.  I did a track and trace using our exchange tracking system which confirmed the alerts were not being emailed. Not sure if there is a better approach for this, but not being a sql
    expert (however I do have someone I can leverage) I am trying to see if I can somehow extract this information using powershell.
    Secondary general question:  How can I find out the current size of our scom 2007 database and the number of objkects\servers being monitored? This is prep work for a migration over to 2012.
    Thanks in advance for the help!

    1. what scom group a specific server belongs to
    function Get-GroupNames {
     [cmdletbinding()]
     param($computerFQDN)
     $containmentRel = Get-RelationshipClass -name:’Microsoft.SystemCenter.InstanceGroupContainsEntities’
    $computerClass = Get-MonitoringClass -name:”Microsoft.Windows.Computer”
    $criteria = [string]::Format(“PrincipalName = ‘{0}’”,$computerFQDN)
     try {
     $computer = Get-MonitoringObject -monitoringClass:$computerClass -criteria:$criteria
     $relatedObjects = $computer.GetMonitoringRelationshipObjectsWhereTarget($containmentRel,[Microsoft.EnterpriseManagement.Configuration.DerivedClassTraversalDepth]::Recursive,[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive)
     catch {
     $_
     write-host “An error occurred while querying groups of $computerFQDN”
    foreach($group in $relatedObjects)
     [array]$Groups = $groups + $group.SourceMonitoringObject.DisplayName
     if($groups) {
     return $groups
     } else {
     write-host “No groups available for $computerFQDN”
    Usage:
     Get-GroupName -ComputerFQDN myserver1
    for detail, pls. refer to
    http://techibee.com/powershell/powershell-get-scom-groups-of-a-computer-account/1129
    Roger

  • Bpc 7.5 - not sending data on a specific application

    Hi I use SAP BPC 7.5 SP7 patch 1 with Microsoft Sql Server 2008.
    I moved my AppSet from a server 32bit to a server 64bit.
    On 32bit server everything works fine.
    On 64bit server (64bit configurations written in BPC installation guide applied + no error in Server Manager > DIagnostic): I can't send data on a specific application I have.
    On 64bit server: I precessed all dimensions and all applications and then I even optimize. Nothing change.
    I have to applications: A and B.
    On Application A I can send data correctly.
    On application B in my Input schedules when I send data: everything seems to work fine but afer data refresh on my sheet the value disappear and nothing is written into FactWB table. No error displayed.
    Those input scheules are the same I have and working on 32 bit server.
    No errors into Windows event viewer so... what can I check or do more? How can I fix it?
    Edited by: Francesco Andolfi on Feb 10, 2012 7:56 PM

    Hi Francesco,
    have you tried modify application on B?
    have tried if you can send data through a new simple input schedule?
    Kind regards
    Roberto
    Edited by: Roberto Vidotti on Feb 10, 2012 8:35 PM

  • How to restrict number of hits from a browser, within a specific interval.

    Hi,
    we have a web app in which user clicks on a specific submit continously. This fills up the server threads and other users trying to login either get a timeout or page not found. my questions ---
    1. Is there a way to configure weblogic to timeout the httprequest and also the underlying thead which is doing the work.
    2. Is there a way to restrict number of requests from a client within a specific interval..
    thanks in advance..

    Hello Benita
    Set the dialog type of your search help = 'A' (dialog depends on set of values).
    Regards
      Uwe

  • Exporting one specific pdf form field data to a specific webpage field

    Hello there.
    I am currently creating a form in which I need to export one specific pdf form field data to a specific webpage field to avoid typing it again or hitting ctrl+c and then ctrl+v to the webpage, as there are several records that need to be copied and pasted.
    I read that there is no access to the clipboard within pdf therefore, would like to know if there is any way to do that without accessing the clipboard.
    I am a newbie and have been learning by searching the forums and Google, therefore, would appreciate any insight on whether or not this is possible using javascript or the "submit form" funcion.
    Any help is greatly appreciated!

    Hi George, thanks for your response!
    The main issue I have is that this web page is in fact a government page in which I have to manually copy and paste information.
    I have no idea how to automate this process - I have access to the scripts on the page to see what I am able to do, but since I do not have much experience (only very basic javascripting), any other insight would be great!

  • How to get 2 Dates of a specific day From a Pay period

    Hi
    I have a date range (Pay period). now from the start date i Need to find out both Dates of a specific day of that Pay period.
    For Example If i know the date range is
    01/06/2007 to  01/19/2007
    Then I need to know what are the dates for both Saturdays.
    Here it should be 01.06.2007 and 01.13.2007.
    Please help. I always award points. Thanks
    Message was edited by:
            Anwarul Kabir

    Hi,
    Please try this.
    PARAMETERS: P_START LIKE SY-DATUM,
                P_END   LIKE SY-DATUM.
    DATA: DAYS    TYPE I,
          WEEKDAY LIKE DTRESR-WEEKDAY.
    DAYS = P_END - P_START.
    DO DAYS TIMES.
      CALL FUNCTION 'DATE_TO_DAY'
        EXPORTING
          DATE    = P_START
        IMPORTING
          WEEKDAY = WEEKDAY.
      IF WEEKDAY = 'Sat.'.
        WRITE: / P_START.
      ENDIF.
      P_START = P_START + 1.
    ENDDO.
    Regards,
    Ferry Lianto

  • Need to copy Data from a specific Html Tag

    Hello,
    I am trying to use CF to access website and capture data from a specific tag to the end of that tag and store same in a csv file or database.
    The tag based search of an open file is where I am not able to get any head way. Any one has done this?

    You'll need to use a regular expression for that. CF supports regular expressions with the REFind, REFindNoCase and REReplace functions. Here's an example of using regular expressions to capture the value within an HTML tag:
    http://www.javamex.com/tutorials/regular_expressions/example_scraping_html.shtml
    It's in Java, but the syntax for regular expressions is the same in CF.
    Dave Watts, CTO, Fig Leaf Software
    http://www.figleaf.com/
    http://training.figleaf.com/
    Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
    GSA Schedule, and provides the highest caliber vendor-authorized
    instruction at our training centers, online, or onsite.
    Read this before you post:
    http://forums.adobe.com/thread/607238

  • Cellular data only for specific apps

    Is there a way by which i can enable cellular data only for specific apps? Lets suppose i want only mail and viber to run on cellular. So how do i enable cellular network only for viber and mail

    Hello all,
    I have been using the iPhone 4S for about a year and I never had problems untill a few days back. Since about a week, my 3G settings for applications installed automatically reset.
    Path >> iPhone screen >> Settings >> Mobile(Cellular) >> Use Mobile Data For >> "List of all apps installed"
    Against each application, you have an option to either enable / disable the mobile data usage:
    Eg:
    App Store          (swipe left to disable || swipe right to enable)
    Contacts          (swipe left to disable || swipe right to enable)
    Facebook          (swipe left to disable || swipe right to enable)
    Facetime          (swipe left to disable || swipe right to enable)
    Weather          (swipe left to disable || swipe right to enable)
    You Tube          (swipe left to disable || swipe right to enable)
    etc...
    Problem:
    If I don't want You Tube to use mobile data, I would normally swipe left to disable thus the application will not start / stream any music if its on 3G/4G. Since a few days, whenever I disable the option for any app... go back to the main screen and recheck the settings, I see its enabled again!
    The error I see when I start the app is:
    MOBILE DATA IS TURNED OFF FOR "YOU TUBE"
    You can turn on mobile data for this app in settings
    <Settings>     <OK>
    When I go back to settings... I see the option is enabled.
    Now I dont know what and how this happened all of a sudden. I have tried resetting the network settings for my iPhone, and it has not helped me.
    My iPhone is updated to OS 7.0.4 and all apps are updated.
    Anyone can help me on this error and how do I fix this?
    FYI... I have no problems connecting to WiFi at all!

  • What is a data group and what use is it for?

    CAn some one explain me the concept of data group in EBS. What is it used for ? How does it enhance the security of Oracle Apps data ?
    I know that Data groups are used while defining a responsibility and are meant for data security purpose. But I want to know the conceptual details behind it.
    Thanks.

    Ok.. so with a data group we can have data security at Oracle schema level. I hope my understanding is correct.
    I can create a data base user called Sinha and create a data group with this user/schema.
    Now when I create a data group with this schema and assign it to a responsibility, which in turn is assigned to a user, he/she will have access only to those objects which are present in the schema called Sinha, right ?
    Now as all the objects in Oracle Apps are created under the Apps schema, what use this new data group (and schema) is of ?

  • How can I link specific cells in two different speadsheets so the data from a specific cell in spreadsheet A automatically updates in a specific cell in spreadsheet B. It works in Xcel- Any ideas?

    How can I link specific cells in two different tables so the data from a specific cell in table A automatically updates in a specific cell in table B? It works in Xcel- Any ideas?

    (1) your title ask the way to link different spreadsheets.
    In Numberland, a spreadsheet is an entire document.
    There is no way to link different documents.
    (2) in the message, you ask the way to link different tables.
    This feature is available and is described in iWork Formulas and Functions User Guide (which is available for free from the Help menu).
    Getting the info just requires a simple search in this available resource !
    Yvan KOENIG (VALLAURIS, France) 14 mai 2011 10:37:50

Maybe you are looking for

  • Placing an array of objects onto stage

    I am trying to place an array of objects onto a stage where they drop vertically. I have been able to do it by placing the array objects into an object called "bag" but have found that the bag object only contains the last array object id so I can no

  • Problems with cmdlets within the Exchange 2013 powershell

    Hi, i've following problem: I can't access all possible powershell cmdlets within the exchange powershell. For example following cmdlet is missing: "Get-Queue". Also we have trouble with some other cmdlets: Get-Mailbox only lists one of 30 mailboxes

  • X-Forwarded-For HTTP header behaviour with web dispatcher

    can anybody specify the behavior of Web Dispatcher regarding the X-Forwarded-For HTTP header? When a client accesses SAP EP via proxy1, proxy2 and Web Dispatcher in this order, is it guaranteed that the format of the X-Forwarded-For HTTP header that

  • Force Closing when trying to edit contacts

    Lately after receiving my new replacement droid with the Froyo already installed; every time i try to edit a contact i get force closed error messages? Is anyone else receiving this message? 

  • Waiting for network time"?

    I thought I had set up Apple TV correctly, and paired it with my silver remote it came with, but whenever I turn it on now, the screen says "Waiting for network time". Has anyone else had this issue? I can't seem to find the answer online or in the m