Average Function for Timestemp Columns

HI
Tab_A have two timestemp columns Send_Time and Receipt_Time
To find the difference of two columns I do (Receipt_Time - Send_Time) as 3rd_Col
I wish to find average of this 3rd_Col in seconds i.e. avg (Send_Time - Receipt_Time)
Please advise how?
Wishes
Jawad

Hi,
Use Average clause with group by.
Need any more clarification, post your sql query, sample input and sample output
Regards

Similar Messages

  • Average sum for a column in ALV tree layout

    Hi,
    I've trying to set an average sum for a column in an ALV tree report.  In the field catalog i set the DO_SUM field to 'X' and this will do a total sum, but I can't find out how in the code to do the average sum.
    Also to get round this I was going to just set a default display variant with the "average" sum option saved after i had manually selected the columns and set it to this.  Problem with this is that when i re-run it, the sum comes back as a total rather than an average.  I have tried setting display variants on the SAP example ALV tree programs and the same thing happens.
    Does anyone know how i can get round this?
    Cheers
    Matt.

    Hi,
    In addition to setting DO_SUM = 'X' you need to specify function in H_FTYPE field. It should be set to 'AVG' in your case.
    ls_fielcat-do_sum = 'X'.
    ls_fieldcat-h_ftype = 'AVG.

  • Sorting a Collection with dynamic columns using a custom compare function for multiple columns

    I need help and ideas on how to sort a ListCollectionView.  My problem is complicated by 3 requirements-
         1. The column values contain HTML tags that needs to be removed before sorting (use custom compareFunction to strip HTML)
         2. The columns are dynamic, so dataField names are not known at compile time (need a single compareFunction for all columns)
         3. The data is used in an AdvancedDataGrid so multi-column sorting is required
    I have figured out how to solve any 2 of the 3 requirements.  However, I am having difficulties supporting all 3 requirements.
    Any help or ideas would be greatly appreciated.  Thanks.

    After playing with this some more I think I've figured out a solution.  This seems to work in initial testing.  Also, there is not a need to capture the current sort column in the headerRelease event which many offered solutions suggested.  Another benefit to this solution is that keyboard initiated sorting is handled also.  Whereas the headerRelease event is only triggered by a mouse click on the column header and special handling is required if the user uses the keyboard to access the column header.
    One point that I don't understand is how ascending/decending order is determined.  Behavior seems to be different between a single SortField versus multiple SortFields.  Notice how the compareResults are handled for the different situations.  Anyone out there know why???
     private function colSortCompareFunction(obj1:Object, obj2:Object, fields:Array = null):int{
         var compareResults:int = 0; 
         var newObj1:Object = new Object(); 
         var newObj2:Object = new Object();
          // should not be a condition that is met   
         if (_dataProviderDetails.sort.fields == null)     {
              var s:Sort = new Sort(); 
              var f:Function = s.compareFunction; 
              return f.call(null, obj1, obj2, fields);     }
         // when a single column is selected for sorting   
         else if (_dataProviderDetails.sort.fields.length == 1)     {
              var firstFld:SortField = _dataProviderDetails.sort.fields[0];
              newObj1[firstFld.name] = stripHTML(obj1[firstFld.name]as String);          newObj2[firstFld.name] = stripHTML(obj2[firstFld.name]
    as String);
              compareResults = ObjectUtil.compare(newObj1[firstFld.name], newObj2[firstFld.name]);
               return compareResults;     }
         // when multiple columns are selected for sorting   
         else       {
              for each (var fld:SortField in _dataProviderDetails.sort.fields)          {
                   newObj1[fld.name] = stripHTML(obj1[fld.name]
    as String);               newObj2[fld.name] = stripHTML(obj2[fld.name]
    as String);
                   compareResults = ObjectUtil.compare(newObj1[fld.name], newObj2[fld.name]);
                    if (compareResults != 0)               {
                        if (fld.descending)                    {
                             return compareResults * -1;                    }
                        else                      {
                             return compareResults;                    }
               return compareResults;     }
    Does anyone see any problems with this solution?
    NOTE:  stripHTML(String) is a simple function using regular expression to remove HTML tags.
    Thx

  • SUM function for a column made 'on the fly'

    I have access to a database, however only SELECT statements can be run on the database. Basically the database lists switches, these switches can have up to 20 computers connected to them but some do not. I need to know the switches which contail less than 20 computers so I know where there is space for more computers (I've wrote the code for this already). I also need something to keep a tally/total for the number of spare spaces left so I can run the script and go 'ok we have a total of 20 spare places for computers theres 10 on this switch and 10 on this one'.
    I just need to get the sum funtion working for the column that I've created 'on the fly', the column revealing the number of spare slots, heres the code I've got so far:
    SELECT switch, COUNT(*) as "Servers", 20 - COUNT(*) as "Spare slots"
    from dedicated_servers
    where switch like 'rs%'
    GROUP by switch
    HAVING COUNT(switch) < 20
    order by Servers;
    Which gives the following:
    | switch | Servers | Spare slots |
    | rsj14-1.dc | 12 | 8 |
    | rsj12-1.dc | 15 | 5 |
    | rsi2-2.dc | 16 | 4 |
    | rsj13-1.dc | 16 | 4 |
    | rsi2-1.dc | 16 | 4 |
    Just need something at the end saying TOTAL=25

    OK I'll have to make em up though, but they are something like this for one switch:
    INSERT INTO dedicated_servers (switch, server_number, switch_socket)
    VALUES (rsj-1.dc, 100, 18)
    On switch rsj-1.dc there can be upto 20 servers (the server_number is the primary key)
    Message was edited by:
    slowpoke115

  • Instr function for table column

    hi,
    lets consider the basic soctt.emp table. i need to check for the first occurence of 'a' in the Ename column in emp table.
    select instr(ename,'a') from empabove function does not seem to work
    Please advise.
    Regards

    Hi,
    sri wrote:
    but how would be the query if we have ,(comma) in place of 'A'.
    select instr(ename , ',') from empwill this work.What happens when you try it?
    If it's not doing what you want, then post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data. Dplain how you get those results from that data.
    If you can show the problem using commonly available tables (such as those in the scott or hr schemas) then you don't need to post any sample data, just the results and explanation.
    Always say which version of Oracle you're using.

  • Aggregate Function for Text Column???

    Hi,
    Is there a way to group a column's values appearing in multiple rows ( all having some similarity) to be grouped into one single column in one Single Row??
    To be more precise,
    do we have an Aggregate function which would group values ( may be using commas for separation) for a single column appearing in multiple rows when "grouped By" on some condition.

    See here:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    Rgds.

  • Is there any functionality for AVERAGE in ALV, like do_sum, subtot?

    Hi Experts,
    In my_alv report, am doing sub/totals for prices, by using do_sum, subtot functions.........fine. But, I need to do/display the AVERAGE value for Discount % column?
    Is there any functionality for AVERAGE in ALV, like do_sum, subtot?
    thanq

    hi
    check these links out
    http://www.sapfans.com/forums/viewtopic.php?t=20386
    http://www.sapfans.com/forums/viewtopic.php?t=85191
    http://www.sapfans.com/forums/viewtopic.php?t=88401
    http://www.sapfans.com/forums/viewtopic.php?t=17335
    regards
    vijay
    reward points if helpful

  • Functions in a Column

    If I am working on a function for a column, eg =IF(ISBLANK(D11),0,1) , but I want to apply it so that each cell auto updates to the same row as the column (the formula is in column E and I want E11 to look at D11, E12 to look at D12, etc) how do I do that
    without having to copy and paste to each cell and changing the numbers?  Sorry for the noob question, but I'm stumped

    Select the cell with the formula (E11).
    Do one of the following:
    The lower right corner of the selected cell is a small square, the so-called fill handle. Use the mouse to drag the fill handle down to the cells below. This is called 'filling down'. Excel will automatically adjust the reference to cell D11 to D12, D13,
    etc.
    Or copy E11 to the clipboard (Ctrl+C), then select the cells below, e.g. E12:E49. Paste (Ctrl+V) will copy the formula and adjust it automatically.
    A cell reference such as D11 is called relative. Excel will adjust it when you fill or copy it.
    If you don't want the reference to change, make it absolute by inserting $ before the column letter and/or row number: $D$11 will
    not be adjusted. An easy way to make a reference absolute is to select it and press F4. F4 actually toggles between four states: D11, $D$11, D$11 and $D11.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Max function for table having no rows

    Hi All
    I have a table in which initially no rows. I am running max() function for a column and then wnats to add 1.
    But when no rows there below code in not working
    select max(code) into p_maxCode from cms_codedetails where codetypeid=0;
    p_maxCode:=p_maxCode+1;
    dbms_output.PUT_LINE('p_maxCode: '||p_maxCode);
    result is:
    p_maxCode:
    How can I handle the this to get 1 if no rows in the table .

    Hi !
    Max function in yur case returns NULL and then
    null + <anything> ... is still null
    You can do
    p_maxCode:=nvl(p_maxCode,0)+1;
    or
    select nvl(max(code),0) into p_maxCode from cms_codedetails where codetypeid=0;
    Of course if YOU have decide that null in this case can be treated as 0
    T

  • Calling a user defined function as default value for a column

    Hi All
    Can we call a user defined function as default value for a column ??
    for example:
    create or replace  function test1  return number is
    begin
    return 10;
    end;
    create table testt
    (id  as test1,
      name varchar2(20));
    getting error:
    Error at line 1
    ORA-02000: missing ( keywordThanks
    Ashwani
    Edited by: Ashwani on Jan 16, 2012 1:19 AM

    Hi;
    For your issue i suggest close your thread here as changing thread status to answered and move it to Forum Home » Database » SQL and PL/SQL which you can get more quick response
    Regard
    Helios

  • Oracle XML functions return tags for null columns.

    I am currently writing a SOAP Message base on a SQL statement formatted as XML. However, I am having problems with Oracle XML functions not returning tags for null columns as seen in my example below. Is the a way to get Oracle XML functions to return empty tags for null column?
    CREATE TABLE FOREXAMPLE_TABLE (COLUMN_1 VARCHAR2 (4000),
    COLUMN_2 VARCHAR2 (4000),
    COLUMN_3 VARCHAR2 (4000));
    INSERT INTO FOREXAMPLE_TABLE (COLUMN_2)
    VALUES ('This column is not null');
    COMMIT;
    SELECT XMLELEMENT ( "soap:Envelope",
    XMLATTRIBUTES ( 'http://schemas.xmlsoap.org/soap/envelope/' AS "xmlns:soap"),
    XMLELEMENT ( "soap:Body",
    XMLATTRIBUTES ( 'http://Custom_Column/types/' AS "xmlns:ns1"),
    XMLELEMENT ( "ns1:New_Instance",
    XMLELEMENT ( "ns1:Input_XMLDoc",
    XMLFOREST(fe.COLUMN_1 as "Column_1",
    fe.COLUMN_2 as "Column_2",
    fe.COLUMN_3 as "Column_3"))))) as xml
    FROM FOREXAMPLE_TABLE fe
    The results returned from the select statement.
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body xmlns:ns1="http://Custom_Column/types/"><ns1:New_Instance>
    <ns1:Input_XMLDoc><Column_2>This column is not null</Column_2>
    </ns1:Input_XMLDoc></ns1:New_Instance></soap:Body></soap:Envelope>
    The desired results for the select statement.
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body xmlns:ns1="http://Custom_Column/types/"><ns1:New_Instance>
    <ns1:Input_XMLDoc><Column_1></Column_1>
    <Column_2>This column is not null</Column_2><Column_3></Column_3>
    </ns1:Input_XMLDoc></ns1:New_Instance></soap:Body></soap:Envelope>
    jeeman

    An alternative may be be to use xmlconcat instead of xmlforest:
    Time Start: 30.06.2007 18:52:41
    PL/SQL procedure successfully completed.
    michaels>  select xmlelement
              ("soap:Envelope",
               xmlattributes
                      ('http://schemas.xmlsoap.org/soap/envelope/' as "xmlns:soap"),
               xmlelement
                    ("soap:Body",
                     xmlattributes ('http://Custom_Column/types/' as "xmlns:ns1"),
                     xmlelement ("ns1:New_Instance",
                                 xmlelement ("ns1:Input_XMLDoc",
                                             xmlconcat (xmlelement("Column_1", fe.column_1),
                                                        xmlelement("Column_2", fe.column_2),
                                                        xmlelement("Column_3", fe.column_3)
              ).extract('.').getstringval() as xml
      from (select null column_1, 'This column is not null' column_2,
                   null column_3
              from dual) fe
    XML                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
      <soap:Body xmlns:ns1="http://Custom_Column/types/">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
        <ns1:New_Instance>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
          <ns1:Input_XMLDoc>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
            <Column_1/>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
            <Column_2>This column is not null</Column_2>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
            <Column_3/>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
          </ns1:Input_XMLDoc>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
        </ns1:New_Instance>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
      </soap:Body>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    </soap:Envelope>                                                                                             

  • Use of Average Function in repository

    Hi,
    I need to use the average function on a derived column in the repository.
    The requirement is to find different between two dates and then perform an average for a particular time period on the difference.
    AVG(TIMESTAMPDIFF(SQL_TSI_DAY, Deposit_date, Withdrawal_Date))..This is the sample of my requirement in the repository.
    I am not able to use it as I get the following error..
    [38083] The Attribute defines a measure using an obsolete method.
    How can I get past this and use the average function in the repository..I cannot pass this to the answers part as this is a adhoc reporting DM.
    Any help will be greatly appreciated.
    This requirement is for OBIEE 10.1.3
    Thanks
    Edited by: vjbez1 on Dec 3, 2012 6:24 AM

    OBIEE doesn't support aggregate functions in formulas that are built from logical columns. Use logical columns that already have an aggregate function defined to build formulas. Alternatively, add this under the General section of your NQSConfig.ini file: SUPPORT_OBSOLETE_MEASURES = YES;
    Please mark if helpful/correct.

  • Average function in ALV Report

    Hi ,
    I am doing Subtotal in ALV by Grouping the Fields. Instead of Using Subtotal i want to Use Average of
    (Total / Quantity) in AlV. Is there any function availabile for doing Average in ALV Reports.
    Point will be definately awarded .\
    Kamal

    >  I am doing Subtotal in ALV by Grouping the Fields. Instead of Using Subtotal i want to Use Average of
    > (Total / Quantity) in AlV. Is there any function availabile for doing Average in ALV Reports.
    >
    It is possible to show the Average using the FIELDCATALOG-DO_SUM = 'C'. for the column/field which you want the Average.
    FIELDCATALOG-DO_SUM = 'C'. "<-----Avergage
    Read the Rules , Don't use Forbidden words...

  • How to take the Average of a DATEDIFF column with NULL values?

    I am building an SSRS report that can display the average of a calculated datediff column in dd/hh/mm format with the following formula:
    =Avg(IIF(Fields!LastCorrectedDate.Value is nothing,0, DATEDIFF("n",cdate(Fields!LastCorrectedDate.Value),cdate(Fields!
    LastSignDate.Value)) \(60*24) & ":" & DATEDIFF("n",cdate(Fields!LastCorrectedDate.Value),cdate(Fields!
    LastSignDate.Value)) mod (60*24)\60  & ":" & DATEDIFF("n",cdate(Fields!LastCorrectedDate.Value),cdate(Fields!
    LastSignDate.Value)) mod (60*24) - (((DATEDIFF("n",cdate(Fields!LastCorrectedDate.Value),cdate(Fields!
    LastSignDate.Value)) mod (60*24))\60)*60) ))
    SSRS does not raise any errors with the formula and I have used the same formula for other columns without issue. I have noticed that this column includes null values which I think may be the problem. When the reports runs, it returns #ERROR on the column
    but does not give a reason why.  I am using SSRS report builder with visual basic logic as opposed to embedding SQL. Any help or feedback would be greatly appreciated.

    Hi No Ragrets,
    According to your description, you want to calculate the average for the date time difference. Right?
    In Reporting Services, Avg() function is only available for numeric values. In this scenario, the DateDiff() function to calculate the minutes difference will return a number. So we can do average calculation based on the return values first. Then we format
    it as a time. We have tested this case in our local environment. Please try the following expression:
    =floor(avg(DateDiff("n",Fields!StartDate.Value,Fields!EndDate.Value))) \(24*60) &":"&
    floor(avg(DateDiff("n",Fields!StartDate.Value,Fields!EndDate.Value))/60 mod 24 )&":"&
    floor(avg(DateDiff("n",Fields!StartDate.Value,Fields!EndDate.Value))) mod 60
    The result looks like below:
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • "moving average" function

    is there any "moving average" formula to the functions area ?

    Pedi
    You can build your own moving average calculation. Not difficult, just define the range for the AVERAGE function and then Fill the expression down the data column.
    Jerry

Maybe you are looking for