Query on time period

Hi,
I have to make a query returning sum(xxx) for given period of 3 h.
table looks like:
start end xxx
0
3
6
Any suggestions are appreciated
Dobby

Consider grouping by the trunc(end/3) or trunc(start/3) -- depending on whether you assign a range to a 3 hour block by when it starts or when it ends.
SELECT min(start) || ' - ' || max(end) AS period, SUM(xxx) AS sum_xxx
FROM your_table
GROUP BY trunc(end/3);

Similar Messages

  • Daily max(value) query for time period

    I am looking to get the maximum value for every 24 hour period for a month. So for example my date range can be defined by...
    select to_date('&date','mm yyyy')-1 + level as DateRange
    from dual
    connect by level <= '&days'
    ...where I can provide the first date of the month and number of days in the month or a lesser value if less time is required. So, the results of the above query plus 24 for the range. I thought a some googling would provide me what I needed, but my search came up empty.
    I was hoping to do something like this...
    select utctime, max(value) from table where utctime between....
    Any guidance would be much appreciated!
    Thanks!

    Zewbie wrote:
    Sorry about that...Oracle 10.2.0.5
    create table x (utctime date,
    pointnumber int,
    value float)
    insert into x values (to_date('02022012 232221','mmddyyyy hh24miss'), 10, 3.245);
    insert into x values (to_date('02022012 202202','mmddyyyy hh24miss'), 13, 14.5);
    insert into x values (to_date('02024012 103421','mmddyyyy hh24miss'), 10, 23.245);
    insert into x values (to_date('02024012 042528','mmddyyyy hh24miss'), 10, 33.245);
    insert into x values (to_date('02028012 022321','mmddyyyy hh24miss'), 14, 32.245);
    insert into x values (to_date('02028012 205221','mmddyyyy hh24miss'), 10, 2.245);
    insert into x values (to_date('02029012 211421','mmddyyyy hh24miss'), 14, 1.4345);
    insert into x values (to_date('02029012 082221','mmddyyyy hh24miss'), 10, 3.245);Do you have dates 7000 years in the future, or ido you have typos?
    So a query of the above would provide max daily value based on a pointnumber such as 10 for a given period.What are the results you want from the given data?
    What role does pointnumber play in this problem?
    If you want something like this:
    A_DATE      POINTNUMBER  MAX_VALUE
    02-Feb-2012          10      3.245
    02-Feb-2012          13       14.5
    02-Feb-2012          14
    03-Feb-2012          10
    03-Feb-2012          13
    03-Feb-2012          14for the 2 days starting with February 2, 2012, then you can do this:
    WITH   days_wanted     AS
         SELECT  DATE '2012-02-02'     -- starting date
                  + LEVEL - 1     AS a_date
         FROM     dual
         CONNECT BY     LEVEL  <= 2     -- number of days wanted
    SELECT    d.a_date
    ,       x.pointnumber
    ,       MAX (x.value)   AS max_value
    FROM       days_wanted  d
    LEFT OUTER JOIN        x  PARTITION BY (x.pointnumber)
                                   ON  TRUNC (x.utctime)  = d.a_date
    -- WHERE  x.pointnumber       = 10         -- If wanted
    GROUP BY  d.a_date, x.pointnumber
    ORDER BY  d.a_date, x.pointnumber
    ;

  • Query to search between two specific dates and time period

    Hi,
    Need a query to search between two particular dates and time period
    Like i want to search table having one date field .
    Suppose the date range is '01-JUL-06' and '01-AUG-06' and time frame
    is 23:00:00 to 08:00:00
    i.e i want to search between dates 01 july to 01 aug and also within the time frame i.e 23:00 to 08:00 hrs only

    The general principle is
    SELECT * FROM your_table
    WHERE some_date BEWTEEN to_date('01-JUL-06') and to_date('01-AUG-06' )+0.99999
    AND  ( some_date <= trunc(some_date)+8/24
               OR  some_date >= trunc(some_date)+23/24 )
    /Cheers, APC

  • How to find the cpu usage per query for a time period

    Hi All,
    Is there a way to find the cpu used per query for a given time period?
    DB:10.2.0.5
    OS:AIX
    Thanks

    user13364377 wrote:
    if there are multiple queries starting at the same time, then what to do?Handle:      user13364377
    Status Level:      Newbie (10)
    Registered:      Jul 5, 2010
    Total Posts:      264
    Total Questions:      113 (84 unresolved)
    why so many unanswered questions?
    clarify your question
    same SQL multiple times from different sessions?
    or
    different SQLs from different sessions?

  • 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Not permitting time period to be overlapped....

    Hi ,
    I have the following table..in Oracle10g Standard Edition:
    SQL> desc ref_dikaioum_meres_ektos_edras;
    Name                          Type      Nullable Default Comments
    SEQ_CODE_DIKAIOUM_EKTOS_EDRAS NUMBER(5)                          
    SEQ_CODE_ERGAZOMENOY_TYPE_ID  NUMBER(5) Y                        
    DATES_APO                     DATE      Y                        
    DATES_EOS                     DATE      Y                        
    DAYS                          NUMBER(3) Y  How is it possible to define a businness rule(a constraint) that for a specific "SEQ_CODE_ERGAZOMENOY" not to permit new records to be inserted if the time_period(dates_apo...means date_from) and (dates_eos... means dates_to) is overlapped to another time period....
    For example:
    If there is a record .... seq_code_ergazomenoy_type_id=12 , dates_apo= '01/01/2007' , dates_eos='31/12/2007' ...
    and the user tries to insert a record like this.....
    .... seq_code_ergazomenoy_type_id=12 , dates_apo= '01/05/2007' , dates_eos='31/10/2007' ...
    or
    .... seq_code_ergazomenoy_type_id=12 , dates_apo= '01/05/2007' , dates_eos='31/01/2008' ...
    or
    .....seq_code_ergazomenoy_type_id=12 , dates_apo= '01/07/2006' , dates_eos='31/01/2007' ...
    or
    .....seq_code_ergazomenoy_type_id=12 , dates_apo= '01/01/2006' , dates_eos='31/01/2008' ...
    the system won't permit to insert it.....
    thanks a lot
    Simon

    Have you considered using 3360's suggestion of a materialized view with a check constraint?
    Like I said, it's really difficult to do this correctly, especially with triggers. In particular:
    1. Your package (or temporary table, or whatever) needs to able to store an arbitrary number of "records", not just one. If it only stores one, it won't correctly handle statements like INSERT INTO...SELECT...FROM where the SELECT returns more than one row. Tom's example uses an "index by" table of ROWIDs for this purpose.
    2. You need some sort of locking mechanism because you can't "see" changes that other, concurrent transactions have made but haven't committed yet. If you can't see them, you can't be certain that they their changes don't conflict with yours. The lock needs to prevent more than one transaction from inserting or updating rows for a given "domain" ("seq_code_ergazomenoy_type_id" I think in your case) at the same time. Tom's example uses DBMS_LOCK for this purpose, but...
    3. To handle serializable transactions, the lock needs to "persist" after you commit, at least until all other transactions that started before you committed have committed or rolled back themselves. DBMS_LOCK doesn't do this, but SELECT...FOR UPDATE can.
    In any case, if, for the moment, we ignore these important but difficult-to-address issues, and we ignore the "seq_code_dikaioum_ektos_edras" column (since I am not clear on how you want to use it), the logic for the query that finds the overlap (like in your after statement trigger) should be something like this (for a single record):
    declare
        n integer;
    begin
        select
            count(*)
        into
            n
        from
            dual
        where
            exists
                select
                    null
                from
                    ref_dikaioum_meres_ektos_edras     
                where
                    seq_code_ergazomenoy_type_id = pkg_ref_dikaioum_meres_chk.v_code_ergazomenou      
                    and
                    dates_apo < pkg_ref_dikaioum_meres_chk.v_dates_eos
                    and
                    dates_eos > pkg_ref_dikaioum_meres_chk.v_dates_apo
        if (n > 0) then
            raise_application_error(-20020,'error_message');
        end if;
    end;Tom's example loops through the rows identified in the "index by" table to perform this check for each "new" row.
    The "materialized view" approach basically does the same thing using a similar query. It "counts" the number of overlapping rows. When a transaction commits, the materialized view refreshes. A check constraint on the "count" column in the underlying table (that stores the "materialized" results of the view) prevents the "count" from being anything other than zero. If it is, the refresh fails.
    I wonder if your code is giving "false positives" because of the way you're using "seq_code_dikaioum_ektos_edras". Your SELECT statement could be returning the row that was just inserted because it has the greatest "seq_code_dikaioum_ektos_edras" and the row "overlaps with itself".
    Hope this helps.

  • Oracle apps OTL Time period LOV

    Hi,
    I need the time period LOV (data for example : September 30,2012 - October 06,2012) as a LOV. I need to utlilise similar LOV for my custom form. I could see an existing LOV for self servuce time responsibility for creating time card. But I don't see a valid select/code for this self service page when opened from jdev. It looks like something dynamic.
    Similar LOV is also there in the apps form time keeper entry find box. I am unable to find the code associated with the LOV directly.
    Anyone is aware of any such LOV for which I can get any select query or a code for the same. I am still trying to achieve the same with some research.
    Regards,
    Ad

    Hi Pillair,
    I believe he is looking for the underlying table ....
    select *
    from fnd_lookup_values
    where lookup_type = 'MTL_TIME_FENCE'
    Hope this helps.
    Cheers
    JD

  • Oracle (SQL) support for Temporal / time period based data

    Beyond standard SQL (DATE type etc. and <,>, LEAST, GREATEST, etc.) does Oracle offer anything to help handle time period based data? E.g. overlapping periods, joins when gaps in time periods from 2+ tables, period contiguity checks, etc. I've developed various SQL query techniques, but they're all rather cumbersome using standard SQL.
    Oracle Spatial offers geo-location support - is there anything similar for temporal query support?
    Any good books / docs on the subject?

    Check out Workspace manager for limited out of the box temporal support.
    You may also want to have a read through this series of articles about temporal database systems. They aren't Oracle specific, but may help you with your temporal system design.

  • Query optimium time

    Hi friends
    how to check the query optimum time, whether the query is taking proper time for execution or not, i mean to say query is taking proper time or more time than usual, if its taking more time how to resolve it.
    please forward some links

    Hi,
    You can go to ST03 and see the complete statistics of the query.....How much time it took and at what level(OLAP, DB, Frontend) it took maximum time.
    Got to ST03 --> select BI Workload --> Select the time period for which you want to see the details
    Select Query Runtimes and there you can select Aggregation by Query on the right hand side .
    Hope this helps.

  • Query Execution time Is Unpredictable

    Hello All,
    ENVIRONMENT_ :- ORACLE 10g
    Basically i m running a very complex query in sql prompt
    My query is_
    SELECT A.EMPLID, E.EMAIL_ADDR, E.NAME, A.DEPTID, TO_CHAR(H.CMPNY_SENIORITY_DT,'YYYY-MM-DD'), TO_CHAR(H.SERVICE_DT,'YYYY-MM-DD'), TO_CHAR(A.TERMINATION_DT,'YYYY-MM-DD'), A.SUPERVISOR_ID, 'fr', A.P1_REPORT_LOCATION, A.P1_STATUS_CATEGORY, E.EMAIL_ADDR, H.P1_PAYROLL_ID, TO_CHAR(SYSDATE,'YYYY-MM-DD')
    FROM PS_JOB A, PS_P1_EMPLTBL_SRCH A1, PS_PER_ORG_ASGN H, PS_PERSONAL_DATA E, PS_P1_PERSTBL_SRCH E1
    WHERE A.EMPLID = A1.EMPLID
    AND A.EMPL_RCD = A1.EMPL_RCD
    AND A1.OPRID = 'xyz'
    AND H.EMPLID = A1.EMPLID
    AND H.EMPL_RCD = A1.EMPL_RCD
    AND E.EMPLID = E1.EMPLID
    AND E1.OPRID = 'xyz'
    AND ( A.COMPANY = 'abc'
    AND A.EFFDT =
    (SELECT MAX(A_ED.EFFDT) FROM PS_JOB A_ED
    WHERE A.EMPLID = A_ED.EMPLID
    AND A.EMPL_RCD = A_ED.EMPL_RCD
    AND A_ED.EFFDT <= SYSDATE)
    AND A.EFFSEQ =
    (SELECT MAX(A_ES.EFFSEQ) FROM PS_JOB A_ES
    WHERE A.EMPLID = A_ES.EMPLID
    AND A.EMPL_RCD = A_ES.EMPL_RCD
    AND A.EFFDT = A_ES.EFFDT)
    AND A.EMPLID = H.EMPLID
    AND A.EMPL_RCD = H.EMPL_RCD
    AND A.EMPLID = E.EMPLID
    AND ( A.EMPL_CLASS NOT IN ('M','N','O')
    AND NOT ( A.EMPL_CLASS IN ('S','P')
    AND A.EMPL_RCD = 0)
    AND NOT ( A.EMPL_RCD >= 1
    AND A.EMPL_CLASS = 'D')) )
    The first time i run this query in sql-prompt it takes around 30-35 mins.
    But after an hour or so when i again run the same query(or with slight modifcation like replacing sysdate with sysdate-1) it gives result in 2-3 mins.
    When again i run the above query let say after 2 -3 hours it comes with result in 2-3 mins.
    Now, the absurd behavior is," The next morning i run this query it again takes 30-35 mins. But after an hour or so running it again takes 2-3 mins".
    And this behavior is repeated every day.
    I wanna ask is there sumthing like oracle do some extra work like computing and analyzing the tables first time i run the query. And then store the statistics for sum defined time period. And when i run the query again it gives result fast because it finds the stats in its cache.
    if so then how can i force oracle to skip such activities...
    Thanks
    -pradeep

    Agreed...
    If the current statement has already been processed, the parse operation can skip the two functions in the parsing process: Optimization and Row Source Generation. A soft parse will save a considerable amount of CPU cycles when running a query.
    But a query skip hard parse and go for soft parse only when the exact query has already been parsed.
    But suppose i modify my query a little bit then the parse phase must execute ALL of the parsing steps.i.e. Must do hard parse.
    But even when i modify my query a little bit like making sysdate = sysdate -1 in the above query...It is giving result in 3 mins.
    And even if a query is doing soft parse..performance jumping from 30 mins to 3 mins is quite a lot.
    My question is there sumthing new optimization technique added in oracle 10g. I read somewhere that a query skip hard parse only when exactly same to same query has been run sumtime earlier and modifiying a little bit also will cause hard parsing.
    Correct me if i m wrong.
    Thanks
    --Pradeep                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Query Execution Time for a Query causing ORA-1555

    dear Gurus
    I have ORA-01555 error , earlier I used the Query Duration mentioned in Alert Log and increased the Undo Retention as I did not find th UnDOBLKS column of v$undostat high for the time of occurence of ORA-01555..
    But new ORA-01555 is coming whose query duration exceeds Undo Retention time..
    My question -
    1. Is it possible to accurately find the query duration time besides the Alert Log file ?

    abhishek, as you are using an undo tablespace and have already increased the time that undo data is retained via undo_retention then you might want to consider the following ideas which were useful with 1555 error under manual rbs segment management.
    1- Tune the query. The faster a query runs the less likely a 1555 will occur.
    2- Look at the processing. If a process was reading and updating the same table while committing frequenctly then the process under manual rbs management would basically create its own 1555 error rather than just being the victum of another process changing data and the rbs data being overlaid while the long running query was still running. With undo management the process could be generating more data than can be held for the undo_retention period but because it is committed Oracle has been told it doesn't really have to keep the data for use rolling back a current transaction so it gets discarded to make room for new changes.
    If you find item 2 is true then separating the select from the update will likely eliminate the 1555. You do this by building a driving table that has the keys of the rows to be updated or deleted. Then you use the driver to control accessing the target table.
    3- If the cause of the 1555 is or may be delayed block cleanout then select * from the target prior to running the long running query.
    Realistically you might need to increase the size of the undo tablespace to hold all the change data and the value of the undo_retention parameter to be longer than the job run time. Which brings up back to option 1. Tune every query in the process so that the job run time is reduced to optimal.
    HTH -- Mark D Powell --
    dear mark
    Thanks for the excellent advise..I found that the error is coming because of frequent commits..which is item 2 as u righly mentioned ..
    I think I need to keep a watch on the queries running , I was just trying to find the execution time for the queries..If there is any way to find the query duration without running a trace ..
    regards
    abhishek

  • DB User acccess by time period

    Hi,
    I still a newbie in Oracle 10G. I had been reading up on Oracle 10g but couldn't find any information on controlling DB users access by time period. Meaning, DB user 'A' is only allow to access the DB from 8 am to 9 am daily. Is there any doucmentations i can read up on this feature? Hopefully, someone here can help me with this query.
    Regards.

    If your user name is "A" then you can unlock the user at 8 AM and lock the user at 9 AM daily.
    Create a script and put it on your crontab which run at 8 AM and execute the following command logging by SQL plus.
    alter user A account unlock;
    Create a script and put it on your crontab which run at 9 AM and execute the following command logging by SQL plus.
    alter user A account lock;
    Hope this will help
    Regards
    Asif Kabir

  • 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

  • How to compare data from 2 different time periods

    Hi folks,
    I have a question on approach to a problem. I want to be able to compare data from a common db, but for 2 different time periods. For example I want to see the number of occurences of an instance in my data for today and compare it against occurences a week ago today. What's the best approach for this kind of problem? Is this done with 2 separate queries from 2 sub reports and then compared some how? Any comments on this approach or an other are appreciated.
    TIA bvd

    Follow these steps:
    1) Bring your first time period in your main report.  This will be your first query.
    2) Bring your second time period in a subreport.  This will be your second query.
    3) Bring the values from your subreport into your main report using shared variables.
    4) Lastly, compare the results using formulas in your main report.
    I hope this information proves useful.
    Regards,
    Zack H.

  • Get Time Period Values 12.0

    All,
    Is there any way to get the values of configured Time Periods at runtime. For example get the current  shift start and and end time values?
    Regards,
    Christian

    This little trick is also an excellent way to understand how the time engine works, in a WYSIWYG manner.  If you test your Simulator Tag query template from the Template Editor or WB and select text/xml the answers are revealed.
    A simple Q/A for situations like:
    What happens if I put Time=Today@08:00:00 and Duration = -1 and DurationUnits = D?
    Regards,
    Jeremy

Maybe you are looking for