Using an Aggregate Function in a Sub-SELECT

Ok. I have this Sub-SELECT and I'd like to base my outside query based on the resyult set of my inner Sub-SELECT which contains an Aggregate function.
Is that possible???
Here's the Query...
SELECT *
FROM CUSTPRO.CPM_PND_TRAN_HDR CPMPNDTH
INNER JOIN (SELECT CPMPNDT2.ky_pnd_seq_trans,
CPMPNDT2.id_ba_esco,
CPMPNDT2.ky_ba,
CPMPNDT2.ky_enroll,
MAX(CPMPNDT2.dt_billed_by_css)
FROM CUSTPRO.CPM_PND_TRAN_HDR CPMPNDT2
WHERE CPMPNDT2.ky_pnd_seq_trans IN (6544937)
GROUP BY CPMPNDT2.ky_pnd_seq_trans,
CPMPNDT2.id_ba_esco,
CPMPNDT2.ky_ba,
CPMPNDT2.ky_enroll) DERIVE1
ON CPMPNDTH.id_ba_esco = DERIVE1.id_ba_esco
AND CPMPNDTH.ky_ba = DERIVE1.ky_ba
AND CPMPNDTH.ky_enroll = DERIVE1.ky_enroll
AND CPMPNDTH.dt_billed_by_css = ????DERIVE1.MAX(CPMPNDT2.dt_billed_by_css)???
How can I designate that last qualifier ????....
PSULionRP

You should give your aggregate function a column-alias as in:
SELECT *
FROM   custpro.cpm_pnd_tran_hdr cpmpndth
       INNER JOIN (SELECT   cpmpndt2.ky_pnd_seq_trans,
                            cpmpndt2.id_ba_esco,
                            cpmpndt2.ky_ba,
                            cpmpndt2.ky_enroll,
                            Max(cpmpndt2.dt_billed_by_css) as XXX    -- ADDED THIS.
                   FROM     custpro.cpm_pnd_tran_hdr cpmpndt2
                   WHERE    cpmpndt2.ky_pnd_seq_trans IN (6544937)
                   GROUP BY cpmpndt2.ky_pnd_seq_trans,
                            cpmpndt2.id_ba_esco,
                            cpmpndt2.ky_ba,
                            cpmpndt2.ky_enroll) derive1
         ON cpmpndth.id_ba_esco = derive1.id_ba_esco
            AND cpmpndth.ky_ba = derive1.ky_ba
            AND cpmpndth.ky_enroll = derive1.ky_enroll
            AND cpmpndth.dt_billed_by_css = derive1.XXX
/

Similar Messages

  • How to use a 'Percentofsum' function with a group selection

    Hi All!
    I have created a report using CR XI in which I select on certain records in a database and then further select on those records using a group selection. The displayed records in the subgroup are correct. I sum these totals of the grouping using a formula (Basically 3 formulas, one for Reset, another for the calculation, and the third for the display) since if I just use the 'built in' summary function it will still total all records that were selected before the group selection. My dilemma is that I need to get a percentage of the subtotal based on the total of that grouping. Below is an example of the layout of the report:
                                                                                __Dept %_            Program Bugt             Prgm % of Dept Bud              Cost of %_
    GH#1    ADMIN                                                        100%
    GF#2    LEGAL                                                                                448694                          4.22%                                 12382
    GF#2    CITY MGR                                                                               445414                          4.19%                                 12294
    GF#2    CITY CLERK                                                                           113075                          1.06%                                  3110
    GF#2    COM PROMO                                                                          391657                         3.69%                                  10827
    GF#2   CENTRAL                                                                               1430570                         13.46%                                 39492
    GF#1                                                                      293406                 2829410                                                                      78105
    The "2829410"  is the Display formula I used to accurately calculate the listed program budget numbers. The 3 formulas I used to get that number is a Reset formula (whileprintingrecords;Numbervar W := 0;) located in GH#1, a Calculation formula (whileprintingrecords;Numbervar W := w + Sum ({@Next Year Budget Amount}, {gl_master.a_org}); ) located in GF#2, and a Display formula (whileprintingrecords;Numbervar W;W) located in GF#1. The percentages that currently display in the "Prgm % of Dept Bud" are wrong as they use the 'built in' PercentofSum function when you right click on the filed in the details section and select summary as a percentage of. I need a formula that would do the following calculation: 448694/2829410 = 15.85% and thus the "Cost of %" formula that would do the following calculation: 293406*.1585 = 12382.
    I tried using a similar "Reset", "Calculation", and "Display" formulas but I cannot get to work correctly. Any help would be greatly appreciated.
    Thanks!
    P.S. The reason I am using a group selection is because it is easier than listing out all the accounts (departments) that I do not want in the report and that selection could change from time to time where as what is in the group selection would never change.
    Sorry for long winded explanation.

    Read all about it.
    You'd probably have to write a little wrapper (using JNI) that passes
    parameters and return values around between your C function and
    the JVM.
    kind regards,
    Jos

  • Dynamic SQL and use of aggregate functions

    Hello Forum members,
    I'm trying to create dynamic SQL in a function module and return the MAX value of a field. 
    I am passing in a parameter called CREATE_FIELD_NAME, and my SQL is
    SELECT MAX(CREATE_FIELD_NAME) INTO (CREATE_DATE) FROM (TABLE_NAME).
    I also tried:
    SELECT MAX((CREATE_FIELD_NAME)) INTO (CREATE_DATE) FROM (TABLE_NAME).
    But abap is not recognizing my variable as a variable in either case, but rather, as a field name.
    Anyone know a way around this?
    Thanks in advance,
    Jeff
    Here is my program:
    FUNCTION ZJLSTEST4.
    ""Local Interface:
    *"  IMPORTING
    *"     VALUE(TABLE_NAME) LIKE  MAKT-MAKTX
    *"     VALUE(CREATE_FIELD_NAME) LIKE  MAKT-MAKTX
    *"     VALUE(UPDATE_FIELD_NAME) LIKE  MAKT-MAKTX
    *"  EXPORTING
    *"     VALUE(MAX_DATE) LIKE  SY-DATUM
    DATA: CREATE_DATE LIKE MCHA-ERSDA VALUE '19000101',
          UPDATE_DATE LIKE MCHA-LAEDA VALUE '19000101'.
    SELECT MAX(CREATE_FIELD_NAME) INTO (CREATE_DATE) FROM (TABLE_NAME).
    ENDSELECT.
    *SELECT MAX((UPDATE_FIELD_NAME)) INTO (UPDATE_DATE) FROM (TABLE_NAME).
    *ENDSELECT.
    IF CREATE_DATE > UPDATE_DATE.
       MAX_DATE = CREATE_DATE.
    ELSE.
       MAX_DATE = UPDATE_DATE.
    ENDIF.
    IF MAX_DATE = '19000101'.
    MAX_DATE = SY-DATUM.
    ENDIF.
    ENDFUNCTION.

    Max is right, you need the spaces, as in my example.
    You might like to try this:
    data: l_CREATE_FIELD_NAME) LIKE MAKT-MAKTX,
          l_UPDATE_FIELD_NAME) LIKE MAKT-MAKTX.
    DATA: CREATE_DATE LIKE MCHA-ERSDA VALUE '19000101',
    UPDATE_DATE LIKE MCHA-LAEDA VALUE '19000101'.
    concatenate 'MAX(' create_name ')' into l_create_name separated by space.
    concatenate 'MAX(' update_name ')' into l_update_name separated by space.
    SELECT SINGLE (l_CREATE_FIELD_NAME)
    INTO CREATE_DATE FROM (table_name).
    SELECT SINGLE (l_updATE_FIELD_NAME)
    INTO updATE_DATE FROM (table_name).
    IF CREATE_DATE > UPDATE_DATE.
    MAX_DATE = CREATE_DATE.
    ELSE.
    MAX_DATE = UPDATE_DATE.
    ENDIF.
    IF MAX_DATE = '19000101'.
    MAX_DATE = SY-DATUM.
    ENDIF.
    If it still fails please post the latest abap code for us to check.

  • Update using an aggregate function

    Hi all, while I'm a first time poster I've searched this forum as much as I can for a solution to this problem.
    I'm trying to update an end_time column in a table using the values in the start_time column.
    Here's a simplified example of what I want:
    update table
    set end_time = lag(start_time) over (order by start_time desc)-1;
    So,
    KEY START_TIME
    1 7/1/1998
    2 5/1/1998
    3 4/1/1998
    4 6/1/1995
    becomes
    KEY START_TIME END_TIME
    1 7/1/1998
    2 5/1/1998 6/30/1998
    3 4/1/1998 4/30/1998
    4 6/1/1995 3/31/1998
    While I'd love this statement to be valid, does anyone know an alternative? I'd like to use the merge statement but I'm developing under an oracle 8i environment. I'm saving a pl loop as a last option.

    It is possible that with large data sets this first solution could be slow. The following query may choose full table scans and sort merges which might be more preferred for big tables. Also, the actual updates in the following MERGE will not execute unless the values have actually changed:
    MERGE INTO foo f USING
    SELECT a.start_date, min(b.start_date)-1 end_date
    FROM   foo a,
            foo b
    WHERE  b.start_date(+) > a.start_date
    GROUP BY a.start_date
    ) bar
    ON (f.start_date = bar.start_date)
    WHEN MATCHED THEN UPDATE SET f.end_date = bar.end_date
    WHERE nvl(f.end_date,to_date('01-jan-1900','dd-mon-yyyy')) != nvl(bar.end_date,to_date('01-jan-1900','dd-mon-yyyy'));Greg Pike
    http://www.singlequery.com

  • Select with aggregate functions? i.e. select max(code)...

    The code field on my user table is too small for the key field I want to use but it is still necessary I assume I must generate my own unique value.
    The DBDataSource.Query() method doesn't seem appropriate so should I create a SAPbobsCOM.Recordset and use the DoQuery method to select the maximum value currently in the user table?
    I found some mentions of requiring such a select statement on this board but no examples of the actual code. I'll go ahead and try the DoQuery method unless I hear of something more appropriate.
    Also, I saw a comment that a future release of SAP would have a larger code field for user tables but obviously that didn't happen in 6.7.
    Thanks for any comments.
    Bill Faulk

    Here's what I came up with...
    If you are happy with 99,999,999 records instead of 4,294,967,295 then I guess you can forego the hexadecimal bit. I'd welcome any alternatives if someone has one.
    With the hex:
    private string GetNextKey(string strTable)
        SAPbobsCOM.Recordset rs =
            (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
        rs.DoQuery("select isnull(max(code),'00000000') from [" + strTable + "]");
        string strCode = (string)rs.Fields.Item(0).Value;
        int intKey = Convert.ToInt32(strCode,16) + 1;
        return intKey.ToString("X8");
    No Hex:
    private string GetNextKey(string strTable)
        SAPbobsCOM.Recordset rs =
          (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
        rs.DoQuery("select isnull(max(code),'00000000') from [" + strTable + "]");
        string strCode = (string)rs.Fields.Item(0).Value;
        int intKey = Convert.ToInt32(strCode) + 1;
        return intKey.ToString("00000000");

  • How to use multiple aggregate functions in single query

    hi to all
    The output will be giving first_name,last_name,max(salary),min(salary) and the output will be department wise.From employees table in single query
    output will be:
    first_name|last_name|max(salary)|min(salary)

    SELECT first_name||' '||last_name as ename,
           MIN(sal) KEEP (DENSE_RANK FIRST ORDER BY sal) OVER (PARTITION BY deptno) "Lowest",
           MAX(sal) KEEP (DENSE_RANK LAST ORDER BY sal) OVER (PARTITION BY deptno) "Highest"
    FROM   emp
    ORDER BY deptno, sal;Edited by: Ramio on Jan 10, 2012 10:43 PM

  • Group By Without Using Any Aggregate Function

    L1                                L2
    54654               414.00
    654654               237.60
    654654     
    54654               1,108.80
    654654               1,136.00
    654654               5,956.00
    NOW I WANT OUTPUT LIKE
    L1               L2           sum
    54654     414.00    1,522.80
    54654     1,108.80  1,522.80
    654654     1,136.00  7,329.60
    654654     237.60    7,329.60
    654654     5,956.00  7,329.60
    HERE GROUP IS L1 SO
    L1  54654  414
         54654  1108  SO TOTAL IS 1522

    I USE FOLLOWING LOGIC:-
      sort i_data by lrnum.
       loop at i_data.
           on change of i_data-lrnum.
            if sy-tabix = 1.
              else.
               itab-lrfriegh = tot_sum.
               append itab.
               clear itab.
               clear i_data.
               clear tot_sum.
              endif.
              endon.
            at end of lrnum.
              move i_data to itab.
            endat.
              tot_sum = tot_sum + i_data-afriegh.
            at last.
              itab-lrfriegh = tot_sum.
              append itab.
              clear itab.
              clear i_data.
              clear tot_sum.
            endat.
         endloop.
    CLOSE THREAD
    Edited by: krupa jani on Nov 22, 2008 10:10 AM

  • Select into aggregate function

    Hi,
    I have the following PL/SQL block that I am testing. The block reads a list of values from a local file and inserts the values into a select statement that uses an aggregate function. Here is my code:
    DECLARE
    f utl_file.file_type;
    n COLa%TYPE; --holds values from the file
    v COLb%TYPE; --holds value returned by select statement
    BEGIN
    f := utl_file.fopen(dir,file.txt,'R');
    loop -- loop through file
         utl_file.get_line(f,n);
         if length(n) <> 0 then
              SELECT max(A0.COLa) into v
              FROM (SELECT AOB.COLa, A0.COLb
              FROM TAB1 A0,TAB2 A0B
              WHERE (A0.PK=A0B.PK) and A0B.COLa = n) A0;          
              IF SQL%rowcount = 0 THEN
                   dbms_output.put_line('no rows);
              else
                   dbms_output.put_line(v);
              end if;                    
         end if;     
    end loop;
         utl_file.fclose(f);     
    end;
    Here is the error I get:
    declare
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at "SYS.UTL_FILE", line 98
    ORA-06512: at "SYS.UTL_FILE", line 656
    ORA-06512: at line 12
    I checked the database for the first couple of values in the list and got rows. I also ran a simple PL/sql code to print values in the file successfully. So I dont know why it is returning no data found. From what I understand select into statement using aggregate functions will never raise this exception, so why I am getting this error?
    Thanks.

    Hi,
    Actually, the SELECT ... INTO isn't the problem here.
    Look at the error message:
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at "SYS.UTL_FILE", line 98
    ORA-06512: at "SYS.UTL_FILE", line 656
    ORA-06512: at line 12The error is ocurring inside utl_file, which is being called at line 12 of your code. (That must be
    utl_file.get_line(f,n);)
    Utl_file.get_line raises NO_DATA_FOUND when it reaches the end of the file. (If it didn't you'd have an infinite loop, since your code doesn't have any exit strategy.)
    You can put the call to get_line in its won BEGIN-EXCEPTION-END block, and trap the NO_DATA_FOUND error.
    For example:
    end_of_file := 0;
    WHILE  end_of_file = 0;
    loop -- loop through file
        BEGIN
            utl_file.get_line(f,n);
            if length(n) != 0 then          -- Use !=, because you can't post &lt;&gt; on this site
                SELECT  max(A0B.COLa)     -- No sub-query needed
                into    v
                FROM    TAB1 A0
                ,         TAB2 A0B
                WHERE   (A0.PK   = A0B.PK)
                and         A0B.COLa = n;
                IF SQL%rowcount = 0 THEN     -- Not needed: SELECT MAX ... without GROUP BY always returns 1 row
                    dbms_output.put_line('no rows);
                else
                    dbms_output.put_line(v);
                end if;
            end if;
        EXCEPTION
            WHEN  NO_DATA_FOUND
            THEN
                end_of_file = 1;
        END;
    end loop;Edited by: Frank Kulash on Jul 17, 2009 2:51 PM

  • Selecting both a aggregate function and another field

    I am trying to do something very simple but I am not sure of the syntax.
    I would like to select all of the petid's and find the count of the pets in a given city, both from the same table, Pets.
    Can somebody please help me with this?
    Thanks

    Hi,
    An aggregate function will give you one row of output per group.
    For example, if you use the aggregate COUNT function to get the total number of rows in a whole table, then you can only have one row of output, representing the whole table, so, if I understand the problem, you can't (easily) use an aggregate function.
    Almost all of the aggregate functions have analytic counterparts, that can produce the same results without collapsing the result set into one row per group.
    I think this is what you requested:
    SELECT  petid
    ,       COUNT (*) OVER (PARTITION BY 1)  AS total_cnt
    FROM    pets
    WHERE   city    = 'Paris'  -- or whatever
    ;Sorry, I'm not at a database now, so I can't check, but I think you don't need the PARTITION BY clause, so you can also say:
    ,       COUNT (*) OVER ()  AS total_cntThe keyword OVER marks this as an analytic, rather than an aggregate, function.

  • Using aggregate function pulls an additional table in join

    Hello,
    We're facing a wierd scenario whereby using an aggregate function in a report brings an additional table in the query, which should not be included. Please throw some light on this if you have any idea why this would happen. Here are the details
    OBIEE version: 10.1.3.4
    I pull 2 columns in my report - Col1 (numeric column from Dim A), Col2 (date column from Dim B)
    I have already set an implicit fact column in that subject area (Col3 from Fact X)
    Now when I run this report, the FROM clause of the sql correctly shows Dim A, Dim B, Fact X
    Later, I apply a MAX function on Col2 (date column from Dim B). Ideally, the FROM clause of my sql should still be the same. But here is what happens...
    FROM Dim A, Dim B, Fact X, Fact Y (Bridge table).
    Fact Y is a bridge table that we are using in this subject area. But there is no reason why this table should get pulled in this query just by using an aggregate function in it.
    Your thoughts and insights will be highly appreciated.
    Thanks,
    Vahib

    Did you apply MAX in the aggregate function section? If that is the case, OBIEE is forced to consider logical table for Dim B as a fact and brings in Y as a way to resolve the join between two facts.
    Try setting up a new fact and create MAX column there. See if it resolves that problem or not. You may also want to bring Dim B in the LTS of the main fact and create a column with MAX aggregation. That should work too.

  • Using XML in sub select

    Hmmmm
    Stuck again, it seems as though I am not the sharpest tool in the box when it comes to XML. Boss seems to love XML though....
    In SQL I have the ability to do something similar to the following :
    SELECT * FROM JOBS
    WHERE JOB_ID IN(SELECT JOB_ID WHERE ACTIVE = 1)
    In this scenario no real need to do a sub select however it demonstrates my point.
    Is it possible to achive this using an XML document in my sub select?
    eg something like
    SELECT * FROM JOBS WHERE JOB_ID IN(EXTRACTVALUE(var,xpath JOB_ID)
    If I had a big list would this iterate through each instance of the value I want to join on???

    Have a look at the XML DB technical whitepaper
    http://otn.oracle.com/tech/xml/xmldb/Current/TWP.pdf
    QUERYING AND INDEXING XML WITH ORACLE XML DB on Page 49
    In particular the queries on Page 51

  • Using round off function in where clause

    Hi All,
    I'm trying to use round off function in where clause, I seek help in completing this script.
    WITH CR_Details AS
    (Select
    request_id,
    parent_request_id,
    fcpt.user_concurrent_program_name Request_Name, phase_code, status_code,
    round((fcr.actual_completion_date - fcr.actual_start_date),3) * 24 * 60 as Run_Time,
    round(avg(round(to_number(actual_start_date - fcr.requested_start_date),3) * 1440),2) wait_time,
    fu.User_Name Requestor,
    fcr.argument_text parameters,
    to_char (fcr.requested_start_date, 'MM/DD HH24:mi:SS') requested_start,
    to_char(actual_start_date, 'MM/DD/YY HH24:mi:SS') ACT_START,
    to_char(actual_completion_date, 'MM/DD/YY HH24:mi:SS') ACT_COMP,
    fcr.completion_text
    From
    apps.fnd_concurrent_requests fcr,
    apps.fnd_concurrent_programs fcp,
    apps.fnd_concurrent_programs_tl fcpt,
    apps.fnd_user fu
    Where 1=1
    and fcr.concurrent_program_id = fcp.concurrent_program_id
    and fcp.concurrent_program_id = fcpt.concurrent_program_id
    and fcr.program_application_id = fcp.application_id
    and fcp.application_id = fcpt.application_id
    and fcr.requested_by = fu.user_id
    and fcpt.language = 'US'
    and fcr.actual_start_date like sysdate )
         select crd.*
         from CR_Details crd
         where Run_time <> '0'
         AND wait_time <> '0'
    GROUP BY
    crd.request_id,
    crd.parent_request_id,
    crd.fcpt.user_concurrent_program_name,
    crd.requested_start_date,
    crd.User_Name,
    crd.argument_text,
    crd.actual_completion_date,
    crd.actual_start_date,
    crd.phase_code,
    crd.status_code,
    crd.resubmit_interval,
    crd.completion_text,
    crd.resubmit_interval,
    crd.resubmit_interval_unit_code,
    crd.description
    Not sure about the GROUPBY function referencing the "crd." .

    Hi,
    The best thing for you to do is start over. Start as small as possible, then take baby steps.
    Pick one of the tables; fcr perhaps, and write a query that just uses that table, like this:
    SELECT    *
    FROM       apps.fnd_concurrent_requests     fcr
    WHERE       fcr.actual_start_date          >= TRUNC (SYSDATE)
    AND       fcr.actual_start_dt          <  TRUNC (SYSDATE) + 1
    ;(I think this is what you meant to do when you said "... LIKE SYSDATE".)
    Make sure this little query gets credible results. When that tiny query is working perfectly, add another line or two. You can cut and paste code from what you posted, if that helps you.
    If you get stuck, post the last version of your code that worked perfectly, and the latest version (only a line or two bigger) that has the problem. Describe what the problem is. If you get an error, post the complete error message. In any event, post CREATE TABLE and INSERT statements for all the tables and columns needed to run the query, and the results you want to get from that query.
    When you post any code, format it, so that how the code looks on the screen gives some clues about how it is working.
    When you post any formatted text on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    If you going to use the AVG function in the sub-query, then you probably need to do a GROUP BY in the sub-query.
    If you're not using any aggregate functions (like AVG) in the main query, then you probably don't want to do a GROUP BY in the main query.
    I know this is a lot of work.  I'm sorry.  If there was an easier way, I wouldn't ask you to do all this.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Pivot table in BI Publisher: Different aggregate functions in data columns

    Hi, everyone!
    I`ve got some troubles with pivot table in my rtf-template.
    Here is my xml:
    <ROWSET>
         <ROW>
              <_BI_SUBRF_MO_._MUN_NAME_>МО Петроградский р-н</_BI_SUBRF_MO_._MUN_NAME_>
              <_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>714000003</_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>
              <_BI_MONTH_DEBET_._BI_DEBET_SUM_>0.0</_BI_MONTH_DEBET_._BI_DEBET_SUM_>
              <_BI_CALENDAR_._YEAR__>2009</_BI_CALENDAR_._YEAR__>
              <_BI_CALENDAR_._MONTH__>8</_BI_CALENDAR_._MONTH__>
         </ROW>
         <ROW>
              <_BI_SUBRF_MO_._MUN_NAME_>МО Петроградский р-н</_BI_SUBRF_MO_._MUN_NAME_>
              <_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>714000004</_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>
              <_BI_MONTH_DEBET_._BI_DEBET_SUM_>165.58</_BI_MONTH_DEBET_._BI_DEBET_SUM_>
              <_BI_CALENDAR_._YEAR__>2009</_BI_CALENDAR_._YEAR__>
              <_BI_CALENDAR_._MONTH__>7</_BI_CALENDAR_._MONTH__>
         </ROW>
         <ROW>
              <_BI_SUBRF_MO_._MUN_NAME_>МО Петроградский р-н</_BI_SUBRF_MO_._MUN_NAME_>
              <_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>714000004</_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>
              <_BI_MONTH_DEBET_._BI_DEBET_SUM_>165.58</_BI_MONTH_DEBET_._BI_DEBET_SUM_>
              <_BI_CALENDAR_._YEAR__>2009</_BI_CALENDAR_._YEAR__>
              <_BI_CALENDAR_._MONTH__>7</_BI_CALENDAR_._MONTH__>
         </ROW>
    ...... and so on..
    </ROWSET>
    In the pivot table i`d like to see one row for every BISUBRF_MO_._MUN_NAME_ using BICALENDAR_._YEAR__ and BICALENDAR_._MONTH__ as measures and sum of BIMONTH_DEBET_._BI_DEBET_SUM_ and count of unique (or at least just count of) BIPERS_ACCOUNT_CARD_._BI_PAC_NMB_ in cells.
    I create a pivot table using wizard, everything ok except one thing: as i understand, in pivot table for data in rows we can use only one kind of aggregate function e.g. only sum or only count.
    Is there any way to use different aggregate functions in data cells?
    Thank you

    As you can see, when we use crosstab tag we can specify only one aggregate function for data cells.
    Is there any way to get in XSL-FO (where we can what really happens) instead of:
    <T1>
    <xsl:value-of select="sum(current-group()/_BI_PERS_ACCOUNT_CARD_._BI_PAC_UNID_)"/>
    </T1>
    <T2>
    <xsl:value-of select="sum(current-group()/_BI_MONTH_DEBET_._BI_DEBET_SUM_)"/>
    </T2>
    this
    <T1>
    <xsl:value-of select="sum(current-group()/_BI_PERS_ACCOUNT_CARD_._BI_PAC_UNID_)"/>
    </T1>
    <T2>
    <xsl:value-of select="count(current-group()/_BI_MONTH_DEBET_._BI_DEBET_SUM_)"/>
    </T2>
    Edited by: user12115038 on 26.10.2009 8:08

  • Aggregate Function in SQL subquery

    Hello,
    I am trying to use the following syntax and it is saying I can't use an aggregate function in a subquery. I can't use a GROUP BY in this case because if another field in the project table (such as status) is different, that project will show up twice.
    So in this case I am using this syntax to show the most recent quote within the project.
    SELECT PROJECT.*, QUOTE.QuoteDate, QUOTE.QuoteCode
    FROM PROJECT LEFT JOIN QUOTE ON PROJECT.ProjectID = QUOTE.ProjectID
    WHERE QUOTE.QuoteDate=(SELECT Max(Q.QuoteDate) FROM QUOTE Q WHERE Q.ProjectID = PROJECT.ProjectID);
    My goal here is to show the most recent quote within each project (there can be multiple revisions of a quote within each project). I want to show other fields such as the status of the quote, but if the status is different between quotes, the GROUP BY on that
    field will cause it to be listed more than once. All I want to show is the most recent quote for each project.
    Let me know if this isn't clear.
    Thanks.

    Try the below querySELECT P1.projectID,p1.QuoteDate, Q1.QuoteCode,p1.*
    FROM PROJECT P1 inner join (SELECT Q.ProjectID,Max(Q.QuoteDate) QD FROM QUOTE Q group by Q.ProjectID) Q1 on Q1.ProjectID = P1.ProjectID and Q1.QD=P1.QuoteDate-Prashanth

  • Pivot type query without aggregate function. Transposing

    Hi experts,
    Oracle 11g.
    I have a table (see code example to reproduce), that has a date, a grouping, and the count of that grouping (determined in another query). I need a pivot type query, but, without the aggregate functions. This is just for a report display. I can not seem to figure this one out. Thanks for your help.
    CREATE TABLE temp_task
    AS
       SELECT TO_DATE ('15-NOV-2012') validation_date,
              'GROUP 1' AS group_number,
              42 AS monthly_count
         FROM DUAL
       UNION ALL
       SELECT TO_DATE ('14-DEC-2012') validation_date,
              'GROUP 1' AS group_number,
              33 AS monthly_count
         FROM DUAL
       UNION ALL
       SELECT TO_DATE ('15-NOV-2012') validation_date,
              'GROUP 2' AS group_number,
              10 AS monthly_count
         FROM DUAL
       UNION ALL
       SELECT TO_DATE ('14-DEC-2012') validation_date,
              'GROUP 2' AS group_number,
              32 AS monthly_count
         FROM DUAL
       UNION ALL
       SELECT TO_DATE ('15-NOV-2012') validation_date,
              'GROUP 3' AS group_number,
              7 AS monthly_count
         FROM DUAL
       UNION ALL
       SELECT TO_DATE ('14-DEC-2012') validation_date,
              'GROUP 3' AS group_number,
              9 AS monthly_count
         FROM DUAL;Using only SQL I need to return the following:
    VALIDATION_DATE | GROUP 1 | GROUP 2 | GROUP 3
    11/15/2012 | 42 | 10 | 7
    12/14/2012 | 33 | 32 | 9

    Hi
    You always need to use an aggregate function while pivoting.
    Even if you don't really need any aggregation, that is, when what you see in the table is what you'll get in the result set, you still have to use an aggregate function. If there will only be one value contrinuting to each cell, then you can use MIN or MAX. It won't matter which; since there's only 1 value, that value will be the highest of the 1, and it will also be the lowest. For NUMBER columns, you could also use SUM or AVG.
    SELECT       *
    FROM       temp_task
    PIVOT       ( MIN (monthly_count)
             FOR group_number IN ( 'GROUP 1'
                                 , 'GROUP 2'
                        , 'GROUP 3'
    ORDER BY  validation_date
    ; Output:
    VALIDATION_  'GROUP 1'  'GROUP 2'  'GROUP 3'
    15-Nov-2012         42         10          7
    14-Dec-2012         33         32          9It sounds like you're doing real aggregation someplace, to get monthly_count. Maybe it would be simpler and more efficient to do the pivoting at that point. What is the big picture here? Post some sample data as it is before you compute monthly_count, and the results you want from that data (if different from what you've already posted), and then let's see if we can't aggregte it and pivot it at the same time.

Maybe you are looking for

  • Windows stops responding and closes when I try to print

    I have IE 9 on a vista 64 bit.  Recently I had some problems with print jobs staying in the que.  I resolved that and reinstalled the printer and drivers.  I have a photosmart 5514.  Ever since that day I can't print off a webpage.  Coupons, bank sta

  • Can't open raw files in 32 bit CS4

    Am using Vista 64 bit OS and because I recently purchased Nik Software's Complete Ed was necessary to change from initial set up of PS CS4 64 bit to 32 for their usage compatability. Had Camera Raw 5.0 on 64 bit version, copied camera raw 8bi plug in

  • My IDML file saved in Indesign CC won't open in Indesign 6

    Hello. I am on trial of Indesign CC, and exported a file to an IDML trying to open it on the school computer since they only have previous versions of Indesign. When I try to open my file that I worked on at home in Indesign CC, it won't open in Inde

  • Gnome 3.2 : no Empathy icon in the systray ?

    Hi ! Since I have upgraded to Gnome 3.2, I do not have the Empathy icon in the systray (bottom right of the screen) anymore. So, if I close the Empathy window, it goes somewhere, but I don't know where, and if I want it again, I have to re-launch Emp

  • How to start OC4J in Sun Solaris???

    How to start OC4J in Sun Solaris???