How to get Average of a column in UNION query

Hi All,
I will try to explain the issue as much as I can and If you need clarification on any piece please let me know.
So, I have a Union Query with two sets of Criteria.
The first Criteria Brings the list of Buildings and a set of Measures for it. The second criteria does the same but with a different set of filters.
No I use a UNION between these both criteria and present them in a Pivot view so that we only have one row per each building. The values in each of the criteria in the UNION query are Summed
Ex:
Building
Metric 1
Metric 2
1
20
30
1
25
35
2
40
50
2
45
55
So as I show in the pivot the result is
Building
Metric 1
Metric 2
1
45
65
2
85
105
Now the issue is with the Grand Total.
I want the Grand Total to be an Average of the Buildings. So for Metric 1 The Grand Total should be (45+85)/2 because we have two buildings so the answer should be 65.
How can I get that.
Bottom Line: Need an Average as the Grand Total when the Aggregation rule on the column is set to Sum.
we use 11.1.6.10 version

Hi VJ
What you are asking is impossible in the pivot table itself as you are asking one part of the pivot table to aggregate via one method, and another to aggregate via another method, on the same column ..
It can be done using a calculated item. For your example above you'd use the formula ( $1 + $2) / 2.
.. But thats HIGHLY explicit, and would only work if you KNOW how many buildings will come back in the query.. EVERYTIME.
Why not restructure the query to combine it into a single query using an combinations of filters with OR in between?

Similar Messages

  • How to get list in single column in a query

    Hello.
    I wonder if there is a way of getting with one query (no pl/sql code) a whole list of columns with a separator between them.
    I know I can get that without the separators with a cursor expression:
    SQL> with test_table as (
      2  select 1 col1, 'a' col2 from dual
      3  union
      4  select 1 col1, 'b' col2 from dual
      5  union
      6  select 1 col1, 'c' col2 from dual
      7  union
      8  select 2 col1, 'a' col2 from dual
      9  union
    10  select 2 col1, 'c' col2 from dual
    11  union
    12  select 2 col1, 'd' col2 from dual
    13  union
    14  select 2 col1, 'z' col2 from dual
    15  )
    16  select col1, cursor (select b.col2 from test_table b where b.col1 = a.col1 order by b.col2) col2_list from test_table a
    17  group by col1
    18  /
          COL1 COL2_LIST
             1 CURSOR STATEMENT : 2
    CURSOR STATEMENT : 2
    C
    a
    b
    c
             2 CURSOR STATEMENT : 2
    CURSOR STATEMENT : 2
    C
    a
    c
    d
    zBut the output that I want is (using the separator ';'):
          COL1 COL2_LIST
             1 a;b;c
             2 a;c;d;zI do not know how to handle a cursor expression without using a pl/sql block of function. Can it be done using analytic functions?
    Thanks in advance.

    Like this...
    SQL> ed
    Wrote file afiedt.buf
      1  with test_table as (
      2    select 1 col1, 'a' col2 from dual union
      3    select 1 col1, 'b' col2 from dual union
      4    select 1 col1, 'c' col2 from dual union
      5    select 2 col1, 'a' col2 from dual union
      6    select 2 col1, 'c' col2 from dual union
      7    select 2 col1, 'd' col2 from dual union
      8    select 2 col1, 'z' col2 from dual)
      9  --
    10  select col1, ltrim(sys_connect_by_path(col2,','),',') as col2
    11  from
    12    (select col1, col2, row_number() over (partition by col1 order by col2) rn
    13    from test_table)
    14  where connect_by_isleaf = 1
    15  connect by col1 = prior col1
    16  and rn = prior rn+1
    17* start with rn = 1
    SQL> /
          COL1 COL2
             1 a,b,c
             2 a,c,d,z
    SQL>

  • Sum of columns in union query

    hi, i am using oracle 10g database..
    how to get the sum of column in union query ?
         select * from (select 100 records from dual), (select 50 available from dual)
    union
    select * from (select 200 records from dual), (select 150 available from dual)
    display should be like
                     records         available
                      100               50
                      200               150
    total            300               200thanks ...

    Peter vd Zwan wrote:
    try this:Grouping by records will not produce correct results:
    SQL> with a as
      2  (
      3  select * from (select 100 records from dual), (select 50 available from dual)
      4  union
      5  select * from (select 100 records from dual), (select 100 available from dual)
      6  union
      7  select * from (select 200 records from dual), (select 150 available from dual)
      8  )
      9  select
    10    case when grouping(records) = 0 then null else 'total' end tot
    11    ,sum(records)   records
    12    ,sum(available) available
    13  from
    14    a
    15  group by
    16  rollup (records)
    17  ;
    TOT      RECORDS  AVAILABLE
                 200        150
                 200        150
    total        400        300
    SQL> select  case grouping(rownum)
      2     when 1 then 'Total'
      3   end display,
      4          sum(records) records,
      5          sum(available) available
      6    from  (
      7            select * from (select 100 records from dual), (select 50 available from dual)
      8           union
      9            select * from (select 100 records from dual), (select 100 available from dual)
    10           union
    11            select * from (select 200 records from dual), (select 150 available from dual)
    12          )
    13    group by rollup(rownum)
    14  /
    DISPL    RECORDS  AVAILABLE
                 100         50
                 100        100
                 200        150
    Total        400        300
    SQL> SY.

  • How to get sum of quantity column in table control

    Hi, expert ,
    Someone can guide me how to get som of qty column in table control ?
    I created a screen with a table control  and has a  qty quantity field .
    I want to show total of qty  in a  field .
    my code like this ...
    PROCESS AFTER INPUT.
      LOOP AT I_tab.
        CHAIN.
           FIELD I_tab-COUNTQTY MODULE  caculate_total_qty .
        endchain.
        MODULE UPDATE_TOTAL_QTY  .
      ENDLOOP.
    but, when I Back to the previous screen
    It's caculate again so I always get wrong Total quantity .
    anyone can help me ...

    Hi , Dhina
    I have another question .
    I use internal table data in table control to update  database table .
    The data in the db will be change ,
    but each record I want to delete in table control , it's still exist in database .
    my code is
    WHEN 'SAVE'
         MODIFY YDSGBT53 FROM TABLE I_YDSGBT53 .
         COMMIT WORK .
      END CASE
    How  to fix my code and let it can change and delete data in database  ?
    or
    when I delete record  in table control I must to delete data in the database too .
    Edited by: TitusFang on Jun 16, 2011 3:21 AM

  • How to get tabs into a column on left edge of Firefox window?

    How to get tabs into a column on left edge of Firefox window?
    I've looked extensively for the answer but haven't found it yet.

    I found the Tree Style Tab ad-on does this.
    Mike

  • How to get number of rows return in SELECT query

    i'm very new in java, i have a question:
    - How to get number of rows return in SELECT query?
    (i use SQL Server 2000 Driver for JDBC and everything are done, i only want to know problems above)
    Thanks.

    make the result set scroll insensitve, do rs.last(), get the row num, and call rs.beforeFirst(), then you can process the result set like you currently do.
             String sql = "select * from testing";
             PreparedStatement ps =
              con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
             ResultSet rs = ps.executeQuery();
             rs.last();
             System.out.println("Row count = " + rs.getRow());
             rs.beforeFirst();~Tim
    NOTE: Ugly, but does the trick.

  • How to get POF object's field value from query result

    hi,all:
    I want to get field value from the query result, my code is below
    Set setResults = cache.entrySet(createFilter("homeAddress.state = 'MA'"));
    for (Iterator iter = setResults.iterator(); iter.hasNext(); )
    Contact c=(Contact)iter.next();
    System.out.println ("firstame####=" + c.getFirstName());
    * but I get error*
    Exception in thread "main" java.lang.ClassCastException: com.tangosol.util.ConverterCollec
    tions$ConverterEntrySet$ConverterEntry cannot be cast to com.oracle.handson.Contact
    at com.oracle.handson.QueryExample.printResults(QueryExample.java:159)
    at com.oracle.handson.QueryExample.query(QueryExample.java:86)
    at com.oracle.handson.QueryExample.main(QueryExample.java:43)
    who can tell me how to get POF object's field value from query result

    Hi,
    If you look at the Java Doc for the entrySet method here http://download.oracle.com/docs/cd/E15357_01/coh.360/e15725/com/tangosol/util/QueryMap.html#entrySet_com_tangosol_util_Filter_ you will see that it returns a Set of Map.Entry instances so you need to do this...
    Set setResults = cache.entrySet(createFilter("homeAddress.state = 'MA'"));
    for (Iterator iter = setResults.iterator(); iter.hasNext(); )
        Map.Entry entry = iter.next();
        Contact c=(Contact)entry.getValue();
        System.out.println ("firstame####=" + c.getFirstName());
    }JK

  • How to get total numbers and total price in query reports

    Hi,
    how to get total numbers and total price in query reports.for example:
    particular item is issued 3 times a week...I need total quantity of item issued
    my query...
    SELECT T0.[DocNum], T1.[ItemCode], T1.[Quantity], T1.[Price] FROM OIGE T0  INNER JOIN IGE1 T1 ON T0.DocEntry = T1.DocEntry WHERE T1.[ItemCode]  Like '%%[%1]%%'  and  T1.[U_WOType]='[%0]'

    Hi,
    Try this:
    SELECT T1.[ItemCode], SUM (T1.[Quantity]) as [Total Quantity], SUM (T1.[Quantity] * T1.[Price]) as [Total Price] FROM OIGE T0  INNER JOIN IGE1 T1 ON T0.DocEntry = T1.DocEntry WHERE T1.[ItemCode]  Like '%%[%1]%%'  and  T1.[U_WOType]='[%0]'
    Group By T1.[ItemCode]
    Beni.

  • How to get a single row column from a viewobject in java?

    I have a class file that goes out and gets a viewobject and sets its where clause
    this is it:
    vcRow = vc.createViewCriteriaRow();
    vcRow.setAttribute("LogonId", "='" + strPcis_Login.toUpperCase() + "'");
    vc.addElement(vcRow);
    vo.applyViewCriteria(vc);
    vo.executeQuery();
    I know this working cause I can watch it in debug..
    but now the problem.
    I've looked in the docs and don't see how one can pull the value of the row it found and place it in a uix page in a textinput area
    how can I get a single row column, in this case the UserName that is in the view object to a string and then place it into my
    uix page? I've looked and looked and don't see a method for this.
    is there a way to take the oracle.cabo.servlet.Page and set a textinput with a viewobject get method?
    what way do you do this and where is it documented?

    is there a way to take the oracle.cabo.servlet.Page and set a textinput with a viewobject get method?
    what way do you do this and where is it documented? What you can do is get the value from your VO and set it somewhere that UIX can data bind to -- as a Page proprety, on HttpSession, etc. This is documented in Chapters 4 (Data Binding) and 5 (Controller) of the UIX Developer's Guide.
    To set a property, you use Page.setProperty(String key, String value). Then, in your UIX file, to make a textInput that has the value pulled from a given page property, use:
    <textInput data:text="key@ctrl:page" />
    -brian
    Team UIX

  • How to get name of a column in a RecordGroup

    Function GetColumnName(pSQL Varchar2, pColumnNo ) return Varchar2 is
    rg_name VARCHAR2(40) := 'rg_tmp';
    rg_id RecordGroup;
    cl_name;
    BEGIN
    rg_id := Create_Group_From_Query( rg_name, pSQL);
    -- How to get columnname i.e. 2 nd column or ( pColumnNo)
    return cl_name
    End;

    ever heard of google?
    http://www.java2s.com/Tutorial/Oracle/0601__System-Packages/Usedbmssqldescribecolumns.htm

  • How to get the selected rows & columns in the table?

    hi everybody,
                         In my application the table is kept inside the event structure.I select the cells  in the table (using mouse) on running time.How to get the selected number of rows & columns in that table?

    Hello,
    You can fill selected values of the table by writing to it or the corresponding property using a property node - the table is just a 2D array of strings.  I think for your "disable" question you are referring to the shortcut menu (when you right click).  If you are using LabVIEW 8.x, you can edit or disable that shortcut menu - just right click on your table at edit time and choose Advanced >> Run-Time Shortcut Menu.
    Best Regards,
    JLS
    Best,
    JLS
    Sixclear

  • How to get the number of columns in a result set???

    hi everyone..
    i am trying to establish a servlet applet communication....
    my applet send the sql query to the servlet as serialised string and then the servlet executes the query...
    Since i need to pass the result back to the applet, i thaught of passing the whole reult set to the applet..but that seems to be not possible..
    so i thaught of storing my result set data in a vector and then pass the vector,but the first problem that i came across is that how to get the number of colums in a result set....
    so is there a way to get the number of columns in a result set...???
    and also i would like to know if it possible to send my whole result set to the applet bye serialization or by any method...???
    thanx in advance

    You shouldn't do. It expenses resources (you should always close the ResultSet and the Statement as fast as possible). Simply gently process it into a Collection or Map of DTO's. Those are serializable.

  • How to get average stock in the inventory management cube?

    Dear all,
    I need to get average stock for a month.
    For example: stock on May 1st is 30kg,  stock on May 2nd is 20kg,etc. I need to add these everyday stock together and divided by the days of the month.
    Now I have a non-cumulative key figure with inflow and outflow for stock. Is any way I can do this without bringing very bad performance?
    Regards,
    Bolun

    cOULD YOU PLEASE EXPLAIN ME HOW DID YOU SOLVE YOUR PROBLEM

  • How to get the constraintlist and column name in a table?

    Hi,
    can anyone please tell me how to get the constraint type ,and it's imposed on columns names in a table.
    Thanks,
    Deekay

    Deekay wrote:
    can anyone please tell me how to get the constraint type ,and it's imposed on columns names in a table.To get constraint type:
    select constraint_type from user_constraints where constraint_name = 'YOUR CONSTRAINT NAME';To get constraint columns:
    SELECT column_name from user_cons_columns where constraint_name = 'YOUR CONSTRAINT NAME';SY.

  • How to get average number of emails per day?

    Hi,
    I need figures on the mail activity (whether inbound ir outbound). I have implemented the imslog.pl. Does this output from imslog.pl answer my question:
    Message load by day (dequeues):
    Date # of dequeues
    16-May-2006 8813
    the # of dequeues is the same as the number of outbound messages (mails that are sent by my mail server)?
    How to get the enqueued stats?
    thanks,

    Hi Linda,
    Email statistics are a tricky thing. Before attempting to collate statistics for any kind of reporting you need to strictly define what you wish to collect and how to define an 'email'.
    For example, if a single email is destined for 10 addresses, is this 1 email or 10. From a virus-scanning point-of-view it's one email, but from a storage perspective it can be 10 (single message store makes this even more complex) and from a delivery-to-external host it can be 5 (assuming 5 distinct email domains).
    For email activity, you can separate this into a few categories (this will also depend on your email infrastructure):
    a. Inbound external email (tcp_local enqueue)
    b. Inbound internal/external email from internal staff (tcp_submit/tcp_auth enqueue)
    c. Inbound internal email (tcp_intranet enqueue)
    d. Outbound external email (tcp_local dequeue)
    e. Local account delivered email (ims-ms dequeue)
    f. Local host delivered email (tcp_intranet dequeue)
    These statistics are all currently available in the imslog.pl output.
    Hopefully I haven't caused more confusion. I find though for reporting it is best to have these definitions clear from the beginning, especially if you are looking for trends over-time.
    Regards,
    Shane.

Maybe you are looking for

  • Forms Client Java Applet waiting several minutes

    Hello, We use Forms 10.1.2.0 and html/javascript/plsql applications. All forms applications are working but we have the problem that from time to time the client java applet must wait minutes until there is an answer from the forms-servlet (especiall

  • Ipod Nano not recognized by itunes but appears on the explorer. Log message

    My ipod doesn't appear on itunes but is recognized by windows. It used to work before. I have found several answers to this problem but no one can't solve the problem : 5R, Terminal Service, Ipod Service, Restore, Reset, Usb, Last version of Itunes..

  • Video won't completely download

    So, I got hooked on LOST and downloaded the second episode from the first season. No problems. I then tried to download the third episode (Tabula Rasa) but it only got to the halfway point then hangs. I then get popup that says there was an error (-3

  • Using 10.6 Server as a virtualized operating system?

    I notice you can get 10.6 Server fairly inexpensively, and I've heard one can run it as a virtualized system.   Here are some questions I have about it: 1. Do I understand correctly it can run in Virtualbox on a Mac that is newer than Lion's initial

  • Locked Account due to change of name details on ne...

    As my current credit card expired i registered my new one, which had slightly different name details. Same account,s ame bank, but name added to reflect my married status. i did not ask the credit card to do this. they jsut did it. As a result Skype