Grouping and the LAG function

Oracle 10.2.0.4 SE - One on OL 5 x 86-64

Trying to write reports on statspack tables. In view of this query
select     
--     s1.ucomment
     w1.event
,     s1.snap_id
,     to_char(s1.snap_time,'dd-Mon-yyyy hh24:mi:ss') snap_time
,     lag(w1.total_waits)
over (order by s1.snap_id) prev_val,
      w1.total_waits - lag(w1.total_waits)
                        over (order by s1.snap_id) delta_val
,     lag(w1.time_waited_micro)
over (order by s1.snap_id) prev_val,
      w1.time_waited_micro - lag(w1.time_waited_micro)
                        over (order by s1.snap_id) delta_val
from      stats$snapshot s1
,     stats$system_event w1
where s1.snap_id = w1.snap_id
  and w1.event = 'db file sequential read'
order by w1.event
,     s1.snap_id
;
EVENT                                                               SNAP_ID SNAP_TIME              PREV_VAL  DELTA_VAL   PREV_VAL  DELTA_VAL
---------------------------------------------------------------- ---------- -------------------- ---------- ---------- ---------- ----------
db file sequential read                                                   1 25-Apr-2013 11:00:51
db file sequential read                                                   2 25-Apr-2013 12:00:51     959235      39179  949588625   29088092
db file sequential read                                                   3 25-Apr-2013 13:00:51     998414      29632  978676717   24938574
db file sequential read                                                   4 25-Apr-2013 14:00:52    1028046      21547 1003615291   23101379

4 rows selected.
Works perfectly. But I would like to delete the ' where... w1.event = 'db file sequential read' and get a report on all events. Of course, simply commenting on this condition means that the first occurrence of an event is "shifted" against the last occurrence of the previous event. Can not find a way to get the logic that do break and start the 'delay' all over again.

You use lag (...) over (partition by the order of the events of snap_id), i.e. "partition by the event" will do lag a ' star on "for each different event

Tags: Database

Similar Questions

  • analytical function and the aggregate function

    What are the analytical function and the aggregate function. What is the difference between them?

    Hello

    Analytic Functions : -.

    Analytical functions calculate a value of aggregation based on a group of lines. They differ from aggregate functions because they return several rows for each group. The Group of rows is called a window and is defined by the analytic_clause. For each line, a sliding window of lines is defined. The window determines the range of lines used for the calculations for the current line. Window sizes can be based on a physical number of rows or a logic as the time interval.
    Analytical functions are the last set of operations performed in a query with the exception of the last ORDER BY clause. Every joint and every WHERE, GROUP BY and HAVING clauses are met before the analytical functions are handled. As a result, analytic functions can only appear in the select list or the ORDER BY clause.
    Analytical functions are commonly used to calculate cumulative aggregates, moving, centered and considered.

    Aggregate functions : -.

    Aggregate functions return a line of single result based on the groups of lines, rather than on the unique lines. Aggregate functions can appear in selection lists, as well as in the HAVING and ORDER BY clauses. They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle Database splits the rows in a table when asked or seen in groups. In a query that contains a GROUP BY clause, the select list items can be aggregation functions, GROUP BY constant expressions or expressions involving one of them. Oracle applies the functions of aggregation for each group of rows and returns a single result for each group line.
    If you omit the GROUP BY clause, Oracle then applies any aggregate functions in the select list for all rows in the table queried or the view. You use aggregate functions in the HAVING clause to eliminate groups of the output based on the results of aggregate functions, rather than the values of the individual lines of the queried table or view.

    Let me know if you feel any problem understanding.
    Thank you.

    Published by: varun4dba on January 27, 2011 15:32

  • Major difference between the Group and the organizational unit?

    Pls explain me what is the difference between the groups and the organization unit in simple terms with an example in real time.

    Hello

    https://en.Wikipedia.org/wiki/Organizational_unit _ (computing)

    https://en.Wikipedia.org/wiki/Group _ (computing)

    See you soon.

  • user belongs to a domain and user does not belong to the local administrator or power users groups, or any custom group and the user is not part of the domain administrators group, but user show that it is admin

    WinXP
    user belongs to a domain and user does not belong to the local administrator or power users groups, or any custom group and the user is not part of the domain administrators group, but user show that it is admin

    I did a gpupdate/force and restart twice PC
    Yet, user indicate it is always admin when we right click on Start menu and see the possibility to open all users

    Hi elena_ad,

    Your question of Windows is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the public on the TechNet site. Please post your question in the below link:

    http://social.technet.Microsoft.com/forums/en/winserverManagement/threads

  • unexpected results of the Group and the merger of processor

    Hi team,

    I use a processor of group and the merger in a process that includes "Store-num" and the "Cust-num" and mergers based on the most common value.

    I have few records store-Num = 42 and a few records store-num = 426. But for the same "Cust-num" for these two stores, store-num ' 426' we replace "42"

    My point is that these documents should not have grouped at all.

    No idea why this happen?

    Kind regards

    Ravi

    Yes, that's correct. Dates will be converted to a string representation of the date.

  • Version 30: I hit the star of bookmarks and the search function disappeared. In addition, b/brands list covers a portion of the tab... can we recover the research?

    FFox itself updated to version 30 - as happens unfortunately. So far, hit the bookmarks star opens a window on the left with a search engine on the top, and the following list of the bmarks. The search engine has now disappeared, and bmarks list covers the actual page, I am browsing...
    Can I pick up the search function? Maybe even put an end to bmarks list maskign who I am through?

    If not, what other browser good reputation can you recommend thus rid myself of this and all future destroyers "improvements"?
    Thank you

    You can install the extension Classic theme restaurant if you want a dedicated toolbar button to open the bookmarks bar.

    You can check the settings of the extension of the CTR through the Options/preferences button on the page "Firefox/tools > Modules > Extensions.

  • Battery GS728TS with interfaces and the LAG problems

    Hello

    We have 2 x GS728TS (running firmware 5.3.0.26) switches connected together in a pile with double stacking cables.

    There are 4 servers connected to the battery through the LAG. Each LAG is composed of 4 members and 2 VLANS, 2 on each switch in the stack. Each server running multiple virtual machines.

    Until recently, everything worked fine. However the last week we have suddenly taken in an issue where some (not all) computer virtual on a host could not communicate with VM on other hosts and vice versa.

    After investigation, we discovered that the entries in the ARP on the troublesome VM table did not contain correct entries. Restart the virtual machine has not resolved this. so I restarted the battery and after a long period of time (15 min) the battery came and most of the questions have disappeared, but not entirely.

    So, I checked the table of addresses on the stack of the switch and found that it contains 'bad' entries as well. It shows that some have learned mac addresses are on specific interfaces instead of a lag, and also sometimes these interfaces are not even part of the specified LAG.

    If I turn off one switch and keep it turned off (or the other) then everything starts working correctly again.

    Anyone have any ideas?

    Thank you

    Shaun

    Hello

    During an extended last night maintenance window, I turned off and removed all the power to the two switches in the battery for about 5 minutes.

    I re-applied then power on both switches and after allowing then to start, check and they now seem to be working properly again.

    I just re-checked the switches (about 8 hours later) and they don't always work very well - no notice or detected problems.

    Concerning

    Shaun

  • Group and the Group of the United Nations

    Hi all

    I'm doing a code can select all the objects,text blocks and layers and then group them all the (CTRL + A) +(CTRL+G) , then I'll add more steps

    After that, I want to make a group of the United Nations again (CTRL + A) +(CTRL+SHIF+G)

    I try with this code but I see a few layers not selected and ungrouped, can anyone help please

    var doc = app.activeDocument;

    doc.selectObjectsOnActiveArtboard ();

    newGroup = app.activeDocument.groupItems.add ();

    for (a = app.activeDocument.layers [0].pageItems.length - 1; a > 0; a)

    {

    app.activeDocument.layers [0] .pageItems [a] .moveToBeginning (newGroup);

    }

    Thank you very much

    app.executeMenuCommand ("selectall");   (CTRL + A)

    app.executeMenuCommand ('group');   (CTRL + G)

    app.executeMenuCommand ('separate');  (CAPS + CTRL + G)

  • Selection of group and the radio text box

    I have a form with a question like: "How did you who are we?" and a radio with some choice group. One of the radio group choice is "other - please describe! When selected, a text box changes to 'read only' and the user can write something. I'm not able to update a record with the user's selection in a field in a table (I can save either text or radio group selection area). Any help? Thank you!

    You should check the value of the selected option button. If it's not ' I have this answer: ", assign the value to $_POST ['Proposal_text'].

    If ((isset($_POST["MM_update"])) & ($_POST ["MM_update"] == "form1")) {}

    If ($_POST ['proposal']! = ' I have this answer: "") {}

    $_POST ['Proposal_text'] = $_POST ['proposal'];

    }


    $updateSQL = sprintf ("UPDATE sarcini SET solutie_6 = %s, introd_6 = %s WHERE id_question = %s",

    GetSQLValueString ($_POST ['Proposal_text'], "text").

    GetSQLValueString ($_POST ["'Full_name"], "text").

    GetSQLValueString ($_POST ['id_question'], "int"));

  • Grouping and the concatenation of data

    SQL> DESC TEST
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     BAND                                               VARCHAR2(2)
     BRANCH_CODE                                        VARCHAR2(4)
     COUNTRY                                            VARCHAR2(3)
     SERVICE_CATEGORY                                   VARCHAR2(2)
     RESIDENTIAL                                        VARCHAR2(1)
     COMMERCIAL                                         VARCHAR2(1)
     ZIP_CODE                                           VARCHAR2(5)
    
    SQL>SELECT BAND, BRANCH_CODE, COUNTRY, SERVICE_CATEGORY, RESIDENTIAL, COMMERCIAL, ZIP_CODE
    FROM TEST
    GROUP BY BAND, BRANCH_CODE, COUNTRY, SERVICE_CATEGORY, RESIDENTIAL, COMMERCIAL, ZIP_CODE
    ORDER BY BAND, BRANCH_CODE, COUNTRY, SERVICE_CATEGORY, RESIDENTIAL, COMMERCIAL;
    
    BA BRAN COU SE R C ZIP_C
    -- ---- --- -- - - -----
    TM 2001 US  PC N Y 32011
    TM 2001 US  PC N Y 56321
    TM 2001 US  PC Y N 01011
    TM 2001 US  PC Y N 01206
    TM 2001 US  PC Y N 01302
    TM 2003 CAN TC Y N 90981
    TQ 2005 BAU PC N Y 98180
    TQ 2005 BAU PC N Y 98321
    TQ 2005 BAU PC N Y 98734
    TQ 2005 BAU PC Y N 93672
    
    10 rows selected.
    I want to extract data by concatenating the zip_code based on the unique combination of other fields:
    And the result should be like:
    BA BRAN COU SE R C ZIP_CODE
    -- ---- --- -- - - ----------
    TM 2001 US  PC N Y 32011|56321
    TM 2001 US  PC Y N 01011|01206|01302
    TM 2003 CAN TC Y N 90981
    TQ 2005 BAU PC N Y 98180|98321|98734
    TQ 2005 BAU PC Y N 93672
    If someone can provide some input would be great...

    Several technical ropes of aggregations (you can void in one: instead of a comma for your needs) for many versions.

    http://www.Oracle-base.com/articles/Misc/StringAggregationTechniques.php

  • Satellite C660-2EL - Wireless n and the F8 function key does not show

    Satellite C660-2EL - Wireless works sometimes, but mostly not. Wired connection is ok. When does not not Fn 8 does not appear and the wireless card does not appear in the devices.
    Pilot was handed in place.

    Have tried reset default and many other things - yesterday was working - light today and not...

    Help!

    Hello

    If the wireless network adapter does not work or its lack in the device, the FN + F8 key combination Manager would not work.
    So the problem is your wireless network card.

    The WLan card driver is missing or malfunctioning of the WiFi chip.
    The device uses the Realtek RTL8188CE WLan card.
    Have you installed the chip RTL8188CE WLan driver?
    Make sure what you've done!

    Otherwise, if the WLan card is not listed in the Manager (no unknown device or Ethernet controller) devices marked with yellow exclamation point I guess that the module is faulty.

  • Query SQL using Group by and the aggregate function

    Hi all

    I need your help in writing a SQL query to achieve the following objectives.

    Scenario:

    I have a table with 3 columns. There are 3 possible values for col3 - success, failure, and error.
    Now I need a query that can give me the summary figures for distinct values for col3 for each GROUP BY col1 and col2 values. When there is no values for col3, then it should return ZERO count.

    The example data:

    Col1 Col2 Col3

    success of ABC 01
    success of ABC 02
    success of ABC 01
    ABC 01 failure
    ABC 01 error
    ABC 02 failure
    ABC 03 error
    XYZ 07 failure

    Power required:

    C1 c2 s_cnt F_cnt E_cnt (title)
    ABC 01 2 1 1
    ABC 02 1 1 0
    03 0 0 1 ABC
    XYZ 07 0 1 0

    s_cnt = number of success; F_cnt = number of failure; E_cnt = number of errors

    Please note that the exit should have 5 columns col1, col2, group of (col1, col2) count (success), group of (col1, col2) count (failure), group of (col1, col2) count (error)
    and wherever there are n ROWS, then it should return ZERO.

    Thanks in advance.

    Kind regards
    Shiva

    Hi, Shiva,

    Welcome to the forum!

    Here's one way:

    SELECT       col1
    ,       col2
    ,       COUNT ( CASE
                          WHEN  col3 = 'success'
                    THEN  1
                      END
                 )          AS s_cnt
    ,       COUNT ( CASE
                          WHEN  col3 = 'failure'
                    THEN  1
                      END
                 )          AS f_cnt
    ,       COUNT ( CASE
                          WHEN  col3 = 'Error'
                    THEN  1
                      END
                 )          AS e_cnt
    FROM       table_x
    GROUP BY  col1
    ,            col2
    ;
    

    Whenever you have a problem, post a small example data (CREATE TABLE and only relevant columns, INSERT statements). If you do not, then don't expect answers, you can get to test.
    Also post the results desired from these data.

  • Palm Desktop 6.2.2. and the search function works only in Windows 7

    Palm Desktop search function does not not in Windows 7 64 bit. Help, please.

    I was able to solve this problem by disabling the compatibility mode and setting the application runs under the administrative name.

  • Microsoft comfort keyboard and the keyboard function keys Tecra A3

    I have a Tecra A3 and that you use with a Microsoft Comfort keyboard. The problem is that since the keyboard drivers have been the function keys (Fn + F2 to change the power mode) installed now realize the funcitons additional IE Fn + F2 also opens the folder my pictures. The strangest on East turn on map of wireless network or off with the switch located on the front of the laptop. This has the effect to load a copy of MS Outlook whenever it is switch extra.
    I have the latest version of Microsoft IntelliType Pro (version 5.20.412.0)

    Any idea on how to solve this problem?

    Hello

    Sorry, but you haven't explained do you have this problem now, using laptop or other external keyboard.

    If the problem persists with the help of an external one I think that you can not use combinations of keys FN + FX of Toshiba. Each external keyboard is specific and in my opinion, you should see s operating manuals and check also all additional functions. I'm also sure that you are able to set up some special keys on your own.

    The problem with the WLAN mixer is very strange. Try to delete the specific Microsoft software and check if the feature is as before.

  • Problem with the startup and the main functions of Council and the mouse

    When I come home from the office window, I have no function keyboard or mouse. When I press F8 at startup, the computer stops with two selections - either 1) continue with rebooting the system 2) Delete restoration data and proceed to system boot menu. I'm hesitant to try (2) - what gives?   After a few minutes, then the computer goes into hibernation.  Any ideas how to get this resolved?  My system is XP Home Edition OS and I have a Dell Dimension 8100.

    Hi Skan_Bill,

    1. you remember to make changes to the computer?

    I suggest you try the steps from the following links in the article and see if it helps:

    Windows XP stops responding at the Welcome screen

    A computer that is running Windows XP or Windows Server 2003 may stop responding when you select the option "Delete restoration data and proceed to system boot menu.

    I hope this helps.

Maybe you are looking for