Want to get sum/avg first 90% records  in each grouped record set.

Hi Gurus,
Need your help or example query which help me to achieve sum/avg first 90% records in each grouped record set. Let me show you the basic query and output and proposed output.
select Pid, Sum(SalesAmt) TotalSaleAmt, Avg(SalesAmt) AvgSaleAmt, count(*) NoOfSales from ProductSales group by Pid;
PID TotalSaleAmt AvgSaleAmt NoOfSales
1 12000 100 120
2 24000 50 480
Now I need for PID =1 TotalSaleAmt of first 90% of NoOfSale i.e.120(this is basically nuber of rows found in PrdocutSales Table).
I hope I am clear enough explain my requirement... I would appreciate if we have some Analytical function available..
Gurus Pls help me asap..
Thanks In adavance...
Srichan.

Now I need for PID =1 TotalSaleAmt of first 90% of NoOfSale i.e.120(this is basically nuber of rows found in PrdocutSales Table).
first 90% should mean first 90% by some order, so in this case, which 108 rows (of the 120) do you want to take into consideration?
with
the_sample as
(select 1 the_pid,10 the_sale,1 the_order from dual union all
select 1 the_pid,20 the_sale,2 the_order from dual union all
select 1 the_pid,15 the_sale,3 the_order from dual union all
select 1 the_pid,12 the_sale,4 the_order from dual union all
select 1 the_pid,12 the_sale,5 the_order from dual union all
select 1 the_pid,13 the_sale,6 the_order from dual union all
select 1 the_pid,19 the_sale,7 the_order from dual union all
select 1 the_pid,11 the_sale,8 the_order from dual union all
select 1 the_pid,15 the_sale,9 the_order from dual union all
select 1 the_pid,12 the_sale,10 the_order from dual union all
select 2 the_pid,25 the_sale,1 the_order from dual union all
select 2 the_pid,22 the_sale,2 the_order from dual union all
select 2 the_pid,22 the_sale,3 the_order from dual union all
select 2 the_pid,23 the_sale,4 the_order from dual union all
select 2 the_pid,29 the_sale,5 the_order from dual union all
select 2 the_pid,21 the_sale,6 the_order from dual union all
select 2 the_pid,25 the_sale,7 the_order from dual union all
select 2 the_pid,22 the_sale,8 the_order from dual
select the_pid,the_sum,the_avg
  from (select the_pid,
               sum(the_sale) over (partition by the_pid order by the_order) the_sum,
               round(avg(the_sale) over (partition by the_pid order by the_order),2) the_avg,
               the_order,
               floor((0.9 * max(the_order) over (partition by the_pid))) to_pick
          from the_sample
where the_order = to_pickRegards
Etbin

Similar Messages

  • How to get sum amount (wrbtr) from table BSIS group by gjahr hkont monat

    Hello! I am new to this forum, and to ABAP. Hope my question is not obvious.
    I want to get sum amount from table BSIS, group by year, period an account. Normally I will try a SQL select like this:
    SELECT gjahr monat hkont sum( wrbtr ) as wrbtr INTO CORRESPONDING FIELDS OF TABLE itab FROM BSIS WHERE (itabcond) GROUP BY gjahr monat hkont .
    The problem is that the amount in field wrbtr is all positive. The result gets wrong. The debet/credit indicator shkzg determines what is positive/negative. How to solve this in the most efficient way? Should I read all accounting documents into an internal table, and loop through them, changing the sign, and then make some new select, or is there a better way?
    Regards Dag-Egil
    Message was edited by:
            Dag-Egil Bull Sletholt

    Here are the objects in the trace list:
    SKB1
    USR05
    TRDIR
    SKA1
    SKAT
    SKB1
    BSIS
    PRPS
    BSAS
    V_LTDX
    USR02
    RFBLG
    V_LTDX
    LTDX
    RTXTH
    RTXTF
    RTXTT
    TRDIR
    The most of this call to this tables returns 1-2 records, apart from BSIS, where it returns 10 records. This is the same as accounting documents in the transaction FBL3N. When i try this again with more records returned I still have no call to table GLT0.

  • Getting sum of each column in 2D array

    hi,
    i want to get sum of each column from 2D array. i did public static void main(String[] args) {
              double sum=0.0;
                   int[][] arr={
                             {1,2,8},
                             {2,2,3},
                             {2,2,5},
                             {1,2,8},
                             {1,1,9},
                             {2,2}
                   int i=0,j=0;
                   int len=arr.length;
                   while(j!=len){
                        sum=0;
                        for(i=0;i<arr.length;i++){
                        sum+=arr[i][j];
                        System.out.println("sum is:" +sum);
                        j++;
         }but it doesnot work for jagged array...somebody please help!
    thankx                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Stop assuming the rows in your matrix are all the same length. Arrays know how long they are. Use that information to determine if the current column exists in that row.

  • Retrieve first 3 records for each id

    Hi there,
    I am having trouble solving this problem. Appreciate for any help.
    tableA
    pidm
    1125
    0034
    tableB
    pidm     term
    1125     2006
    1125     2007
    1125     2009
    1125     2010
    0034 2004
    0034     2006
    0034     2007
    0034 2008
    I want to retrieve only the first 3 records from tableB order by term for each pidm that match to pidm of tableA
    select pidm, term from tableB where pidm in (select pidm from tableA) and rownum < 4
    This only return 3 records instead of 6:
    it should return:
    pidm:     term:
    1125     2006
    1125     2007
    1125     2009
    0034 2004
    0034     2006
    0034     2007
    Thanks

    sql>select pidm, term
      2    from (select a.pidm, b.term, row_number() over (partition by a.pidm order by b.term) rn
      3            from tablea a, tableb b
      4           where b.pidm = a.pidm)
      5   where rn <= 3;
    PIDM TERM
    0034 2004
    0034 2006
    0034 2007
    1125 2006
    1125 2007
    1125 2009
    6 rows selected.

  • How to get first 10 records from the database using JSP

    i want ot get first 10 records from the database and then after clicking the next button in the page,it must show the next precceding 10 records from the database.i am getting the first 10 records .but how to post to the same page to get another preceeding 10 record.

    Search the forums - this has been asked a lot. I usually recommend experimenting with tops and order bys until you're satisfied.
    Kind regards,
      Levi

  • I want to re-installed my soft ware I have OSX 10.6.8 I want to get the icloud but  need to upgrade do I installed the DVD that came with my Imac or do I purchase the upgrade first

    I want to re-installed my software I have OSX 10.6.8 I want to get icloud but I would need to do an upgrade do I first installed my software
    and then purchase the upgrade?

    Jose5235 wrote:
    I want to re-installed my software I have OSX 10.6.8 I want to get icloud but I would need to do an upgrade do I first installed my software
    and then purchase the upgrade?
    Make sure your computer is running smoothly on Snow Leopard OS X 10.6.8
    Create a Backup Before Upgrading...
    Then check your Mac is compatible with Mountain Lion OS X 10.8.x
    Upgrade to Mountain Lion
    With Regard to ML...  Check here for compatibility of 3rd party Software you may be using...
    Power PC Applications are Not Supported...
    http://roaringapps.com/apps:table
    You should also consider more RAM... Get the Maximum you can for your Mac...
    It is important to get the Correct and Matching RAM
    See Here  >  OWC RAM  >  http://www.macsales.com

  • I've got the Macbook Pro with leopard, if i want to get Lion for it, do i have to get snow leopard first? i don't have a mac app store!

    I've got the Macbook Pro with leopard, if i want to get Lion for it, do i have to get snow leopard first? i don't have a mac app store!

    Ian, this might help explain it a bit more:
    http://osxdaily.com/2011/06/07/mac-os-x-10-7-lion-system-requirements/
    It's only available from the store, and you need 10.6.6 to access the store. But if you can download it using 10.6.6 on another machine, you'll be able to install it on a machine meeting the hardware requirements (it doesn't matter which OS was installed on it).

  • Got String= "100 600" and want to get out (length of first number not const

    Ive got String= "100 600" and want to get out
    the value 600 into int.
    Length of first number is not const : it can be 100 or 3000
    How can how do it ?
    10x for the help

    It would depend on the format of your string. If you can gurantee that the format will always be "number number" then you can use the StringTokenizer to split the two numbers and take the second one. The code would look similar to this:
    String s = "100 600";
    StringTokenizer st = new StringTokenizer(s, " ");
    //--- This "scrolls" past the first number.
    st.nextToken();
    String num = st.nextToken();
    The variable num will always have the second number.
    Hope this helps.

  • I want to get a new app for my ipad , but it first asked for apple ID and then asked for verify payment, what should i do?

    I want to get a new app for my ipad , but it first asked for apple ID and then asked for verify payment, what should i do?

    The iTunes Store needs the 3-digit security code from your credit card on the account.  The iPad will display the account information so you can enter this information.  Once you enter the information, purchase the app and it will download.  Sounds like the Apple ID and payment information is not yours (your parents), so discuss this with the account holder.

  • Inbox comes up when as the first option on internet home page. I do not want it and did not request it. It is not in my programmes list and I desperately want to get rid of it and get back to Google. How??

    Inbox comes up as the home page for the internet. I have no idea how it arrived and is not in my programme list. Lots of other people seem to have the same problem and no one has come up with a fix. I want to get rid of Inbox completely.

    i have had mozillafirefox forever and updated my yahoo e-mail and everything was good. went to bring up my yahoo e-mail and it was the classic e-mail, spoke to a yahoo customer care agent we looked at Internet Explorer, and Google Chrome, and the new version of yahoo e-mail is there. i have tried to download the new version of yahoo mail and it wont let me. so they tell me to speak to someone at mozillafirefox, so now i am here w/u asking how do i update my yahoo mail?

  • How to prevent a number field from getting summed?

    I want to display the # of clients per a certain ID number. (In order to show the duplicate records by setting a filter in the # of clients field). However, this works if the ID number is a text field... but it doesn't work if the ID number is a metric of client... or number. It gets summed up, I get the total, and the % of clients turns to be 1.
    Any ideas?
    Thanks

    Example:
    I have 3 clients:
    Column A
    55
    55
    44
    21
    I want the following output:
    55 | 2
    I get the desired result by adding a second column (# of clients) and creating a filter to get results only if the value is > 2.
    The problem is when "Column A" is a number field. If it is a number field, I get total sum of the records (55+55+44+21) and a value of "1" if I add the # of clients column.
    Is it clearer now? ideas?

  • How do I get my old Surround Mixer recording sources back?

    I recently had my computer repaired where I basically had a complete overhaul. In the process they installed a second soundcard (the one that went with the new motherboard) alongside my original Creative Sound Blaster Audigy card (Sound Blaster Audigy Platinum eX). Before, when I would record audio into my computer, I opened the Surround Mixer software and in the record pulldown menu it showed all of the inputs as they relate to my Audigy interface (SPDIF, Aux In 2, Line In 2, etc.). Now when I open the Surround Mixer software, I only get generic options such as Analog Mix, CD Digital, Microphone, etc. and therefore I can't get any outside audio into my computer.
    I figured the computer?was defaulting to the?new sound card so I disabled the onboard audio in my BIOS and then installed the Creative Sound Blaster Series 2 Driver. I clicked on the driver and it said that it needed to uninstall another driver that was already there. The install went a little funny and it got hung up a couple of times. Then, I couldn't get Surround Mixer to work at all so I went to the Creative website and installed Software Auto Update. I downloaded and installed all the critical components?but that also went a little funny. It took about three tries and it didn't seem like it actually finished installing, but when I checked on Auto Update again, it said that I was up to date and that everything had installed. I noticed at the beginning that it installed a new version of Surround Mixer but when I opened it later, it still had those same generic options, not the the ones that match my external interface.
    What do I need to do to get my original settings back?
    Message Edited by audiodrome on 04-30-2009 06:46 PMMessage Edited by audiodrome on 04-30-2009 07:32 [email protected]

    >Re: How do I get my old Surround Mixer recording sources back?p audiodrome,
    Is the external Audigy Dri've properly connected? Does the Plat Ex have the rear jacks? If so, can you record from the rear LineIn or mic jack and play sound files through headphones or speakers? What happens when you run the Creative Diagnostic? What does Device Manager show? Otherwise, yes, uninstall and reinstall the Creative software. If your install CD has a repair option, try that first. However, you may find you need to remove the Audigy from your PC, reboot without it, and then reinstall everything. Some Soundblaster cards don't play well with some integrated soundcards, so you may also want to disable the integrated soundcard in BIOS.
    Message Edited by Katman on 05-04-2009 :00 AM

  • How to get the record set into array?

    Hi,
    I want to get the record set into array in the procedure and do the processing of the array later in procedure.
    below is the stored procedure i am working on:
    procedure bulk_delete_group(p_group_id in Array_GroupListID) as
    begin
    for i in p_group_id.first..p_group_id.last loop
    --Here I have to get the list of user id before deleting group
    SELECT user_id into *<SOME ARRAY>* FROM group_members WHERE group_id = p_group_id(i);
    DELETE group WHERE group_id = p_group_id(i);
    --Process the user id array after group deletion..
    end loop;
    end bulk_delete_group;
    Thanks in advance
    Aditya

    Something like this ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Elapsed: 00:00:00.20
    satyaki>
    satyaki>
    satyaki>select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          9999 SATYAKI    SLS             7698 02-NOV-08      55000       3455         10
          7777 SOURAV     SLS                  14-SEP-08      45000       3400         10
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       4450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       7000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
    13 rows selected.
    Elapsed: 00:00:02.37
    satyaki>
    satyaki>create type np is table of number;
      2  /
    Type created.
    Elapsed: 00:00:03.32
    satyaki>
    satyaki>Create or Replace Procedure myProc(myArray np)
      2  is
      3    i   number(10);  
      4    rec emp%rowtype;  
      5  Begin  
      6    for i in 1..myArray.count
      7    loop  
      8      select *  
      9      into rec 
    10      from emp 
    11      where empno = myArray(i); 
    12     
    13      dbms_output.put_line('Employee No:'||rec.empno||' Name:'||rec.ename); 
    14    end loop; 
    15  End myProc;
    16  /
    Procedure created.
    Elapsed: 00:00:00.88
    satyaki>
    satyaki>
    satyaki>declare
      2    v np:=np(9999,7777);  
      3  begin  
      4    myProc(v);  
      5  end;
      6  /
    Employee No:9999 Name:SATYAKI
    Employee No:7777 Name:SOURAV
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.30
    satyaki>Regards.
    Satyaki De.

  • Need Help in Inserting first ever record

    I need help in inserting my first ever record from an OAF page.
    I've created an AM 'MasterAM', added 'MasterVO' to it. Created a Page CreatePG which has a submit button, id = Apply
    Below is processRequest of CreateCo
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processRequest(pageContext, webBean);
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    if (!pageContext.isFormSubmission()) {
    am.invokeMethod("createRecord", null);
    and below is processFormRequest
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    if (pageContext.getParameter("Apply") != null)
    OAViewObject vo = (OAViewObject)am.findViewObject("MasterVO1");
    am.invokeMethod("apply");
    pageContext.forwardImmediately("OA.jsp?page=/abcd/oracle/apps/per/selfservice/xxdemo/webui/CreatePG",
    null,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    null,
    null,
    true,
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
    Below are 'createRecord' and 'apply' in MasterAMImpl
    public void createRecord(){
    OAViewObject vo = (OAViewObject)getMasterVO1();
    if (!vo.isPreparedForExecution()) {
    vo.executeQuery();
    Row row = vo.createRow();
    vo.insertRow(row);
    row.setNewRowState(Row.STATUS_INITIALIZED);
    public void apply() {
    getTransaction().commit();
    When I run the page, it opens and I try to enter some data and press Apply. it does not insert into the table.
    Could anyone help me out.
    My jdeveloper version is 10.1.3.3.0.3

    I am facing the same issue.
    rows get inserted into the tbale, but only whol columns have the data.
    all the attributes are correctly mapped to view instance and view attribute.
    My VO has 1 EO and , i have joined another table to get desctriptions of the field.
    could that be the problem ?
    ex :
    select item , desc
    from t , master
    where t.cola=master.colb
    table t is the custom table I want the data to go in. but only who columns appear after commiting.
    any clues ?

  • Menu option "other invoice document" gets disabled in MIR7 while Recording

    Hi All,
    I have one requirement when I have to open the parked invoice document ( MIRO) with MIR7.
    I don't want to record each and every field and pass the bdcdata then with call transaction.
    There is one option in MIR7 when under invoicedocumnet->other invoice document i can pass the invoice document number and the fiscal year.
    I have the document number and the fiscal year as i have already parked the document with MIRO.
    so i thought to record this and call the transaction then.
    Problem: When i open MIR7 to record, the menu option invoicedocumnet->other invoice document  gets disabled. I am not able to record this.
    Is there any solution to this? Any BAPI exists ??
    Otherwise i would have to record each and every field to pass the parked data into it ..
    Thanks in advance
    Regards
    Mudit Batra

    Hi,
    check this:
    program: SAPLMR1M
    include: LMR1MI3U
    MODULE (PAI) FCODE_6100
      IF ok-code = fcook.
        mir4_change = 'X'.
        SET PARAMETER ID: 'RBN' FIELD rbkpv-belnr,
                          'GJR' FIELD rbkpv-gjahr,
                          'RBS' FIELD rbkpv-rbstat,
                          'CHG' FIELD mir4_change.
        IF sy-tcode = tcode_mir4.
          LEAVE TO TRANSACTION tcode_mir4 AND SKIP FIRST SCREEN.
        ELSE.
          CALL TRANSACTION tcode_mir4 AND SKIP FIRST SCREEN.
        ENDIF.
      ENDIF.
      SET SCREEN 0. LEAVE SCREEN.
    Best regards.

Maybe you are looking for