get the only recording where the sum is less

Hello
select EMPNO, SAL from EMP

7369     800
7499     1600
7521     1250
7566     2975
7654     1250
7698     2850
7782     2450
7788     3000
7839     5000
7844     1500
7876     1100
7900     950
7902     3000
7934     1300
I need to find all the empno all together (sum) is equal in early 2000 by lowest SAL
IF the sum is below 2000, I can then take an empno, also if, then, the sum will be longer than 2000
It's
800 +.
950 + = 1750
1100 +.
= 2850
I can get the first empno 3 discs = (7369,7900,7876)

If I want to compare with 1750 instead of 2000, I get only two first empno = (7369,7900)

How can he do?

Thanks in advance
SQL> select empno, sal
  2    from (
  3  select empno, sal, sal1, nvl(lag(sal1) over(order by sal),0) lsal
  4    from (select EMPNO, SAL, sum(sal) over(order by sal) sal1 from EMP))
  5  where lsal <2000
  6  /

     EMPNO        SAL
---------- ----------
      7369        800
      7900        950
      7876       1100

SQL> select empno, sal
  2    from (
  3  select empno, sal, sal1, nvl(lag(sal1) over(order by sal),0) lsal
  4    from (select EMPNO, SAL, sum(sal) over(order by sal) sal1 from EMP))
  5  where lsal <1750
  6  /

     EMPNO        SAL
---------- ----------
      7369        800
      7900        950

Tags: Database

Similar Questions

  • to get the sum of the balance_due

    Hi all


    I have this request with me
    SELECT   rac.customer_number, rac.customer_name,
                       su.LOCATION contract, SUBSTR (sa.NAME, 1, 2) bu,
                       ra.purchase_order_date sub_date,
                       ra.invoice_currency_code ccy,RA.PURCHASE_ORDER,ra.trx_number,
                       TRUNC (rad.gl_date) gl_date,
                       SUM
                          (npar_get_invoice_balance (ra.customer_trx_id,
                                                     '08-Sep-2011'
                                                    )
                          ) balance_due
                  FROM ra_customer_trx_all ra,
                       ra_site_uses_all su,
                       ra_cust_trx_line_gl_dist_all rad,
                       ra_customers rac,
                       ra_cust_trx_types_all ty,
                       ra_salesreps_all sa
                 WHERE TRUNC (rad.gl_date) <= '08-Sep-2011'
                   AND ra.bill_to_customer_id = rac.customer_id
                   AND su.site_use_code = 'BILL_TO'
                   AND su.site_use_id = ra.bill_to_site_use_id
                   AND ty.cust_trx_type_id = ra.cust_trx_type_id
                   AND ty.TYPE = 'INV'
                   AND ty.org_id <> -3113
                   AND rad.customer_trx_id = ra.customer_trx_id
                   AND rad.account_class = 'REC'
                   AND rad.latest_rec_flag = 'Y'
                   AND npar_get_invoice_balance (ra.customer_trx_id,
                                                 '08-Sep-2011') <> 0
                   AND sa.salesrep_id(+) = ra.primary_salesrep_id
                   AND sa.org_id(+) <> -3113
                      and ra.purchase_order='2011-0526'
              GROUP BY rac.customer_number,
                       rac.customer_name,
                       su.LOCATION,
                            ra.invoice_currency_code ,
                     ra.trx_number,
                           RA.PURCHASE_ORDER,
                       rad.gl_date,
                       ra.purchase_order_date,
                       ra.invoice_currency_code,
                       SUBSTR (sa.NAME, 1, 2)
    
    with the following output
    
    
    CUSTOMER_NUMBER     CUSTOMER_NAME     CONTRACT     BU     SUB_DATE     CCY     PURCHASE_ORDER     TRX_NUMBER     GL_DATE     BALANCE_DUE
    1002     Joint Operations (KGOC / SAC)     JO/SA88/WO06     12     05/29/2011     KWD     2011-0526     2011-0526-M     05/23/2011     4,773.60
    1002     Joint Operations (KGOC / SAC)     JO/SA88/WO06     12     05/29/2011     KWD     2011-0526     2011-0526-S     05/23/2011     3,559.78
    i require the following output
    CUSTOMER_NUMBER     CUSTOMER_NAME     CONTRACT     BU     SUB_DATE     CCY     PURCHASE_ORDER     TRX_NUMBER     GL_DATE     BALANCE_DUE
    1002     Joint Operations (KGOC / SAC)     JO/SA88/WO06     12     05/29/2011     KWD     2011-0526     2011-0526-M     05/23/2011     8333.38
    1002     Joint Operations (KGOC / SAC)     JO/SA88/WO06     12     05/29/2011     KWD     2011-0526     2011-0526-S     05/23/2011     8333.38
    
    ie balance due is sum of the balances  of trx numbers 2011-0526-M and 2011-0526-S(4733.60+ 3559.78)
    Inorder to get this output I have to avoid the group clause trx number and then only to get the sum of the 8333.38, but I need trx number too in my query.

    Can this be achieved

    kindly help

    thanking in advance

    Something like:

    SELECT   rac.customer_number, rac.customer_name,
                       su.LOCATION contract, SUBSTR (sa.NAME, 1, 2) bu,
                       ra.purchase_order_date sub_date,
                       ra.invoice_currency_code ccy,RA.PURCHASE_ORDER,ra.trx_number,
                       TRUNC (rad.gl_date) gl_date,
                       SUM(
                           SUM(npar_get_invoice_balance(
                                                        ra.customer_trx_id,
                                                        '08-Sep-2011'
                                                       )
                              )
                           OVER(
                                PARTITION BY rac.customer_number,
                                             rac.customer_name,
                                             su.LOCATION,
                                             ra.invoice_currency_code ,
                                             RA.PURCHASE_ORDER,
                                             TRUNC (rad.gl_date),
                                             ra.purchase_order_date,
                                             ra.invoice_currency_code,
                                             SUBSTR (sa.NAME, 1, 2)
                               )
                          ) balance_due
                  FROM ra_customer_trx_all ra,
                       ra_site_uses_all su,
                       ra_cust_trx_line_gl_dist_all rad,
                       ra_customers rac,
                       ra_cust_trx_types_all ty,
                       ra_salesreps_all sa
                 WHERE TRUNC (rad.gl_date) <= '08-Sep-2011'
                   AND ra.bill_to_customer_id = rac.customer_id
                   AND su.site_use_code = 'BILL_TO'
                   AND su.site_use_id = ra.bill_to_site_use_id
                   AND ty.cust_trx_type_id = ra.cust_trx_type_id
                   AND ty.TYPE = 'INV'
                   AND ty.org_id <> -3113
                   AND rad.customer_trx_id = ra.customer_trx_id
                   AND rad.account_class = 'REC'
                   AND rad.latest_rec_flag = 'Y'
                   AND npar_get_invoice_balance (ra.customer_trx_id,
                                                 '08-Sep-2011')  0
                   AND sa.salesrep_id(+) = ra.primary_salesrep_id
                   AND sa.org_id(+)  -3113
                      and ra.purchase_order='2011-0526'
              GROUP BY rac.customer_number,
                       rac.customer_name,
                       su.LOCATION,
                       ra.invoice_currency_code ,
                       ra.trx_number,
                       RA.PURCHASE_ORDER,
                       rad.gl_date,
                       ra.purchase_order_date,
                       ra.invoice_currency_code,
                       SUBSTR (sa.NAME, 1, 2)
    /
    

    SY.

  • How to get the sum of "(qty*rate) as salesValue 'as TotalSalesValue cust_id agenda?"

    Mr President.

    I have to take the column values from3, or 4 tables and two of them need to be multiplied, then get the sum of this value multiplied by using Group by and order clause.

    as below

    cust_id prod name Qty. rate value totalValue
    01one01500500
    01b024008001300

    How to get there

    Select

    cstmr.cust_id CustId,

    PRDT. Name AutoCAD,

    SL.sal_qty SalQty,

    SL.unit_sal_price UnitSalPrice,

    SL.sal_qty * SL.unit_sal_price as SalVal,

    Sum(SL.sal_qty*SL.unit_sal_price) as TotalSalesValue

    Of

    cstmr customer,

    salesLine sl,

    prdt product

    where

    PRDT.prod_id = sl.prod_id

    Group

    cstmr.cust_id,

    PRDT. Name,

    SL.sal_qty,

    SL.unit_sal_price

    order by

    cstmr.cust_id

    Concerning

    Your expected results include values that are not in your input data - there is no M.BOARD product, for example. This is an adaptation of Manik code that will give you the subtotals for each customer:

    SELECT client_name c.nom,

    product_name p.Name,

    SL.sal_qty,

    SL.unit_sal_price,

    SL.sal_qty * SL.unit_sal_price AS salesvalue,

    CASE

    WHEN ROW_NUMBER () OVER (partition by order of c.cust_id p.prod_id desc, sl.sal_id desc) = 1 THEN

    SUM (sl.sal_qty * sl.unit_sal_price) OVER (PARTITION BY c.cust_id)

    END totals

    FROM customer c INNER JOIN sales s ON s.cust_id = c.cust_id

    INNER JOIN salesline sl ON sl.sal_id = s.sal_id

    INNER JOIN product p ON p.prod_id = sl.prod_id

    ORDER BY c.cust_id, p.prod_id, sl.sal_id

    You could get the grand total of lines by the Union in a second query, or by doing something smart using ROLLUP. But I leave that to you because I think you should at least do some of your own homework.

  • try to get the SUM of all of the charges with the having clause

    Hi Oracle users.

    I'm trying to accomplish to get a sum of a series of charges and it should be easy, but I can't get it.

    For example, I have the following.

    Select ACCTLOC,  count(ACCTLOC) AS TOTALP
    FROM BOX_ACCTS_TBL 
     WHERE TIME_REQ > SYSDATE-120
     Group By ACCTLOC
      having (count(ACCTLOC) > 1)
     
     the results are
     
    ACCTLOC   TOTALP
     
    Philly     15970
    NY          8623
    Tacoma        3
    SanFran     195
    Hartford    5
    Miami       4374
    
      
    

    How can I get the SUM of this group? Do I put this in PL SQL and do a procedure to carry out the selection? Is this the way to go on this?
    I appreciate all the comments you can give.

    Thank you!

    with

    query_result as

    (select 'Philly' acctloc, 15970 totalp Union double all the)

    Select "NY", 8623 Union double all the

    Select "Tacoma", 3 double Union all

    Select "SanFran", 195 double Union all

    Select "Hartford", 5 Union double all the

    Select 'Miami', double 4374

    )

    Select acctloc, totalp, sum (totalp) on the_sum, avg (totalp) (on the_avg), ratio_to_report (totalp) (percentages))

    of query_result

    ACCTLOC TOTALP THE_SUM THE_AVG PERCENTAGES
    Philly 15970 29170 4861.66666666666666666666666666666666667 .547480287967089475488515598217346588961
    NY 8623 29170 4861.66666666666666666666666666666666667 .295611930065135413095646211861501542681
    Tacoma 3 29170 4861.66666666666666666666666666666666667 .000102845389098388755570791909496057593
    SanFran 195 29170 4861.66666666666666666666666666666666667 .006684950291395269112101474117243743572
    Hartford 5 29170 4861.66666666666666666666666666666666667 .000171408981830647925951319849160095989
    Miami 4374 29170 4861.66666666666666666666666666666666667 .149948577305450805622214604045251971203

    Concerning

    Etbin

  • How to get the sum of the first row in the previous row?

    Dear gurus... I need to get the sum of a column of the first row of my result set to the previous line based on a condition. I read analytical functions for this but they provide the sum of the first rank to Current Row through declaration "rows between Unbounded preceding and current line. Y at - it a statement that calculates the sum as "rows between Unbounded preceding and previous row?

    Hello

    kamranpathan wrote:
    Dear gurus... I need to get the sum of a column of the first row of my result set to the previous line based on a condition. I read analytical functions for this but they provide the sum of the first rank to Current Row through declaration "rows between Unbounded preceding and current line.

    If you do not explicitly give a windowing clause, then you get the default windowing clause you indicated.
    If you want another clause of windowing, ionclude in the analytic function call.

    Y at - it a statement that calculates the sum as "rows between Unbounded preceding and previous row?

    Yes. The correct syntax for "Previous rank" is «PREVIOUS 1»

    ...  ROWS BETWEEN  UNBOUNDED PRECEDING
                AND        1          PRECEDING
    

    For more information, search for "Analytic Functions" in the manual of the SQL language:
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions004.htm#sthref917

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    You will find the answers better faster if you always provide this information whenever you post a question.

    Published by: Frank Kulash, Sep 17, 2011 17:04
    I just saw Etbin responses.
    As usual, Etbin has a good point. If the column that you are basically cannot be NULL, then it is probably easier to subtract the total current line and use the default windowing clause.
    Even if it can be null, you find may be easier to use this approach.

  • Get the sum of all Member of a hierarchy.

    Hello
    I want to get the sum of each Member in a hierarchy.
    The hierarchy is defined in the strdet table:
    create table strdet
    (costcenterms varchar2(20),     // parent
    costcenterdet varchar2(20),    // child
    lev varchar2(1))
    The values for each object/material by costcenter (child) is defined in the details_det table:
    create table details_det
    (costcenterms varchar2(20),
    eppid varchar2(30) ,
    purchcontyear0 number(4,1) )
    Some examples of data:
    insert into strdet values ('1' , '1.1','2')
    /
    insert into strdet values ('1' , '1.2','2')
    /
    insert into strdet values ('1.1' , '1.1.1','3')
    /
    insert into strdet values ('1.1' , '1.1.2','3')
    /
    insert into strdet values ('1.2' , '1.2.1','3')
    /
    insert into strdet values ('1.2' , '1.2.2','3')
    /
    insert into strdet values ('1.2' , '1.2.3','3')
    /
    insert into strdet values ('1.1.1' , '1.1.1.1','4')
    /
    insert into strdet values ('1.1.1' , '1.1.1.2','4')
    /
    insert into strdet values ('1.1.2' , '1.1.2.1','4')
    /
    insert into strdet values ('1.2.1' , '1.2.1.1','4')
    /
    insert into strdet values ('1.2.1' , '1.2.1.2','4')
    /
    COMMIT;
    insert into details_det values('1.1.1.1','epp1',10);
    insert into details_det values('1.1.1.1','epp2',20);
    insert into details_det values('1.1.1.1','epp3',0);
    insert into details_det values('1.1.1.2','epp1',0);
    insert into details_det values('1.1.2.1','epp2',5);
    insert into details_det values('1.1.2.1','epp4',15);
    insert into details_det values('1.2.1.1','epp1',65);
    insert into details_det values('1.2.1.1','epp2',95);
    insert into details_det values('1.2.1.2','epp1',5);
    commit;
    The desired sql stmt output should be like this:
    costcenter             val
    --------------             ------
    1                        220
    1.1                       55
    1.2                     165
    1.1.1                    30
    1.1.2                    20
    1.2.1                  165
    I wrote the following, so far...
    SQL> select distinct s.costcenterms , sum(purchcontyear0) over(partition by s.costcenterms order by s.costcenterms)
      2        from details_det d , strdet s
      3        where s.costcenterdet=d.costcenterms(+)
      4        start with s.costcenterms='1'
      5             connect by  s.costcenterms = prior s.costcenterdet
      6        order by s.costcenterms
      7  /

    COSTCENTERMS                                                 SUM(PURCHCONTYEAR0)OVER(PARTIT
    ------------------------------------------------------------ ------------------------------
    1.2                                                         
    1.2.1                                                                                   165
    1.1.1                                                                                    30
    1.1.2                                                                                    20
    1                                                           
    1.1                                                         

    6 rows selected
    How should I modify the above sql stmt to get the result you want...?

    Note: I use OracleDB 10 g. v.2

    Thank you very much
    SIM

    sgalaxy wrote:
    Anyway, since I want to use the sql stmt to define a materialized view, all versions of data of hierarchical queries are not allowed... (oracle ora-30361 error...).

    No error on my:

    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    
    SQL> create materialized view x_mv
      2  as
      3  select  grp,
      4          sum(purchcontyear0)
      5    from  (
      6           select  connect_by_root s.costcenterms grp,
      7                   d.purchcontyear0
      8             from  strdet s,
      9                   details_det d
     10                   where s.costcenterdet=d.costcenterms(+)
     11                   connect by s.costcenterms = prior s.costcenterdet
     12          )
     13    group by grp
     14  /
    
    Materialized view created.
    
    SQL> select  *
      2    from  x_mv
      3    order by grp
      4  /
    
    GRP                  SUM(PURCHCONTYEAR0)
    -------------------- -------------------
    1                                    215
    1.1                                   50
    1.1.1                                 30
    1.1.2                                 20
    1.2                                  165
    1.2.1                                165
    
    6 rows selected.
    
    SQL> 
    

    SY.

  • How get the sum of differences in time

    I have the query to get the taken (duration) of time to perform each activity below


    Select (select ep.name PE env_mapping where ep.id = p.bsa_env_id) environment,
    (Select trunc ((Max (ps.actual_end) - Min (ps.actual_start)) * 24 * 60) of ps Highlevel_activity where ps.activity_ID = p.id and ps.out_of_window_flag =' no. "") Actual_duration,
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Apps Patching"and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Apps_Patching,.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, Highlevel_activity ps where de.task_type = ' Patching DB/MT ' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') DB_MT_Patching,.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Shut Down' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Shut_Down,.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Start Up' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Start_Up,.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Vérification' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') audit.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching meadow' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Pre_Patching,.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching Post' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Post_Patching,.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Others' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') others

    activity p where

    I get the output as below

    EnV1 27 April 13 167 54 29 29 15 0 0 67 0
    EnV2 may 3 13 10 20 05 05 0 0 50 0 33


    My requirement is to get the amount for each column which I get on top of the query. How can I change the query above to get as the result below


    EnV1 27 April 13 167 54 29 29 15 0 0 67 0
    EnV2 may 3 13 10 20 05 05 0 0 50 0 33
    177 74 34 34 15 50 67 33 total

    Please help

    Thank you
    Archana

    Hello

    Agowda wrote:
    I have the query to get the taken (duration) of time to perform each activity below

    Select (select ep.name PE env_mapping where ep.id = p.bsa_env_id) environment,
    (Select trunc ((Max (ps.actual_end) - Min (ps.actual_start)) * 24 * 60) of ps Highlevel_activity where ps.activity_ID = p.id and ps.out_of_window_flag =' no. "") Actual_duration,
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Apps Patching"and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Apps_Patching,.


    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, Highlevel_activity ps where de.task_type = ' Patching DB/MT ' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') DB_MT_Patching,.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Shut Down' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Shut_Down,.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Start Up' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Start_Up,.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Vérification' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') audit.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching meadow' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Pre_Patching,.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching Post' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Post_Patching,.
    (select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Others' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') others

    activity p where

    If you make 9 of subqueries to get 9 different columns. It is very inefficient, and it is also difficult to maintain. If you need to change the conditions in subqueries, you will need to do the exact same change at 9 different locations.
    It would be much more effective if you just add de.task_type to the GROUP BY clause and then rotates the results. He could not run 9 times faster, but it probably run 5 times faster.
    See the FAQ forum {message identifier: = 9360005} to find out how.

    I get the output as below

    EnV1 27 April 13 167 54 29 29 15 0 0 67 0
    EnV2 may 3 13 10 20 05 05 0 0 50 0 33

    My requirement is to get the amount for each column which I get on top of the query. How can I change the query above to get as the result below

    EnV1 27 April 13 167 54 29 29 15 0 0 67 0
    EnV2 may 3 13 10 20 05 05 0 0 50 0 33
    177 74 34 34 15 50 67 33 total

    It's a GROUPING DEFINED work, no ACCUMULATION.

    Since you post CREATE TABLE and INSERT statemennts for your sample data, I will use the hr.departments table to show the difference.
    When you GROUP BY N > 1 the expressions, ROLLUP gives you N + 1 levels of totals and subtotals. For example:

    SELECT       department_id
    ,       job_id
    ,       SUM (salary)     AS total_sal
    FROM       hr.employees
    GROUP BY  ROLLUP (department_id, job_id)
    ORDER BY  department_id, job_id
    ;
    

    The above query GROUPs BY s expressions (department_id job_id) so ROLLUP produces 3 sorts of totals:
    (1) total department_id and job_id (e.g. 13000 for department_id = 20 and job_id = "Fatyty" below)
    (2) total Department, including all of the work (e.g. 6000 = 19000 13000 + for department_id = 20) and
    (3) total general for the entire result (e.g. 691416)

    DEPARTMENT_ID JOB_ID      TOTAL_SAL
    ------------- ---------- ----------
               10 AD_ASST          4400
               10                  4400
               20 MK_MAN          13000
               20 MK_REP           6000
               20                 19000
               30 PU_CLERK        13900
               30 PU_MAN          11000
               30                 24900
               40 HR_REP           6500
               40                  6500
               50 SH_CLERK        64300
               50 ST_CLERK        55700
               50 ST_MAN          36400
               50                156400
               60 IT_PROG         28800
               60                 28800
               70 PR_REP          10000
               70                 10000
               80 SA_MAN          61000
               80 SA_REP         243500
               80                304500
               90 AD_PRES         24000
               90 AD_VP           34000
               90                 58000
              100 FI_ACCOUNT      39600
              100 FI_MGR          12008
              100                 51608
              110 AC_ACCOUNT       8300
              110 AC_MGR          12008
              110                 20308
                  SA_REP           7000
                                   7000
                                 691416
    

    You don't want all that: you just want what corresponds in total for each department_id and job_id and total general, without any level of iintermediate. Here's how you can achieve these results using GROUPING SETS instead of ROLLUP:

    SELECT       department_id
    ,       job_id
    ,       SUM (salary)     AS total_sal
    FROM       hr.employees
    GROUP BY  GROUPING SETS ( (department_id, job_id)
                   , ()
                   )
    ORDER BY  department_id, job_id
    ;
    
    DEPARTMENT_ID JOB_ID      TOTAL_SAL
    ------------- ---------- ----------
               10 AD_ASST          4400
               20 MK_MAN          13000
               20 MK_REP           6000
               30 PU_CLERK        13900
               30 PU_MAN          11000
               40 HR_REP           6500
               50 SH_CLERK        64300
               50 ST_CLERK        55700
               50 ST_MAN          36400
               60 IT_PROG         28800
               70 PR_REP          10000
               80 SA_MAN          61000
               80 SA_REP         243500
               90 AD_PRES         24000
               90 AD_VP           34000
              100 FI_ACCOUNT      39600
              100 FI_MGR          12008
              110 AC_ACCOUNT       8300
              110 AC_MGR          12008
                  SA_REP           7000
                                 691416
    

    I hope that answers your question.
    If this isn't the case, post CREATE TABLE and INSERT statements for some examples of data and the results desired from these data.
    Simplify the problem. For example, instead of 9 different task_types, post sample data and results for 3 task_types. Simply mention that you actually 9, and we will find a solution that can be easily adapted for 9.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

    Published by: Frank Kulash on May 27, 2013 10:47

  • Get the sum and lastvalue in one request

    I have this table

    ID

    type

    Balance

    1

    one

    100

    2

    b

    450

    3

    b

    600

    4

    one

    200

    5

    b

    50

    And I need the sum and the last value of the column "balance." How can I me below the result with a single query, without nested query?

    sum

    last

    one

    300

    200

    b

    1100

    50

    Try this:

    Select a separate type,

    Sum (balance) over (partition by type).

    LAST_VALUE (balance) over (partition by RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING id type order)

    from my_table;

    Concerning

    Thomas

  • How can I get the sum of my variables and display the total?

    I wrote on a quiz and have each button by setting a variable, example: http://www.kreativitydesigns.com/Clients/Globus/Monograms/MBA_Test/deliverables/MBA_Quiz.h tml? mode = preview

    However, when it hits the frame of "Rank" to calculate and display the total, it does not appear.

    I do not have the text box named "Grade" on stage and variables have all received a value before entering this framework

    Here is the code used to calcualte and output the result:

    get the value of a variable and store

    var FinalScoreHolder is q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8 + q9 + q10 + q11 + q12 + q13 + q14 + q15 + q16 + q17 + q18 + q19 + q20 + q21 + q22 + q23 + q24 + q25 + q26 + q27 + q28 + q29 + q30 + q31 + q32 + q33 + q34 + q35 + q36 + q37 + q38 + q40 + q39;.

    View rank

    SYM. $("Grade") .html ("you scored" + FinalScoreHolder + "%");

    See the result Page

    If (FinalScoreHolder > = 89) {}

    read the chronology of the given position (ms or label)

    SYM. Play ("Pass");

    } else {}

    read the chronology of the given position (ms or label)

    SYM. Play ("fail");

    }

    Any help would be greatly appreciated.

    Thank you!

    Your code is fine, but it seems that he can not do the values of your questions because if you put the values as below I get the expected result.

    Q1 = 20;

    Q2 = 63;

    Q3 = 12;

    get the value of a variable and store

    var FinalScoreHolder = q1 + q2 + q3;

    View rank

    SYM. $("grade") .html ("you scored" + FinalScoreHolder + "%");

    See the result Page

    If (FinalScoreHolder > = 89) {}

    read the chronology of the given position (ms or label)

    SYM. Play ("Pass");

    } else {}

    read the chronology of the given position (ms or label)

    SYM. Play ("fail");

    }

  • Select only records where the column values are not all equal to zero

    Hi everyone, it seems so easy, but it has left me speechless on the research in a way that is clean, easy to achieve. I know when someone replies, I'm going to kick me. So, let's assume this is what I have:
    with mytable as (
    select 'Type 1' as itemtype, 'JAN' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'FEB' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'MAR' as monthname, 5 as theval from dual union all
    select 'Type 1' as itemtype, 'APR' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'MAY' as monthname, 4 as theval from dual union all
    select 'Type 1' as itemtype, 'JUL' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'AUG' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'SEP' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'OCT' as monthname, 7 as theval from dual union all
    select 'Type 1' as itemtype, 'NOV' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'DEC' as monthname, 2 as theval from dual union all
    
    select 'Type 2' as itemtype, 'JAN' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'FEB' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'MAR' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'APR' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'MAY' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'OCT' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'NOV' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'DEC' as monthname, 0 as theval from dual
    )
    select
      itemtype,
      sum (case monthname when 'JAN' then theval else 0 end) as JAN,
      sum (case monthname when 'FEB' then theval else 0 end) as FEB,
      sum (case monthname when 'MAR' then theval else 0 end) as MAR,
      sum (case monthname when 'APR' then theval else 0 end) as APR,
      sum (case monthname when 'MAY' then theval else 0 end) as MAY,
      sum (case monthname when 'JUN' then theval else 0 end) as JUN,
      sum (case monthname when 'JUL' then theval else 0 end) as JUL,
      sum (case monthname when 'AUG' then theval else 0 end) as AUG,
      sum (case monthname when 'SEP' then theval else 0 end) as SEP,
      sum (case monthname when 'OCT' then theval else 0 end) as OCT,
      sum (case monthname when 'NOV' then theval else 0 end) as NOV,
      sum (case monthname when 'DEC' then theval else 0 end) as DEC
    from mytable
    group by itemtype
    order by itemtype
    I need an external application around it or something which will select only 'Type 1'... that is, if all months are each equal to zero, do not include the record in the result set.

    In summary to get a total of zero is not an option, because I could have-15 and + 15 in different columns, in which case, the recording should be displayed.

    Something as simple as... 'not the case (oct = 0 and 0 nov and dec = 0...) at the end is all it seems to me necessary. I thought to add a case for each column clause, but that seems not very effective. Ideas?

    Thanks in advance!
    Mark

    Edit... I know not what follows will work using the MINUS operator, but my actual query is really huge, and I don't want to have to write it twice...
    {code}
    Select
    ItemType,
    sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
    sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
    sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
    sum (case monthname when "APR" then Val else 0 end) as APR.
    sum (case when monthname 'MAY', then Val else 0 end) either.
    sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
    sum (case monthname when "JUL" then Val else 0 end) as JUL,.
    sum (case monthname when "AUG" then Val else 0 end) as AUG.
    sum (case monthname when "MS" then Val else 0 end) as MS.
    sum (case monthname when "OCTS" then Val else 0 end) OCT.
    sum (case monthname when "NOV" then Val else 0 end) as NOV.
    sum (case monthname when 'DEC' then Val else 0 end) as DEC
    FROM MyTable
    Group of itemtype

    less

    Select
    ItemType,
    Jan, Feb, mar, Apr, may, June, July, August, Sept, oct, nov, dec
    de)
    Select
    ItemType,
    sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
    sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
    sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
    sum (case monthname when "APR" then Val else 0 end) as APR.
    sum (case when monthname 'MAY', then Val else 0 end) either.
    sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
    sum (case monthname when "JUL" then Val else 0 end) as JUL,.
    sum (case monthname when "AUG" then Val else 0 end) as AUG.
    sum (case monthname when "MS" then Val else 0 end) as MS.
    sum (case monthname when "OCTS" then Val else 0 end) OCT.
    sum (case monthname when "NOV" then Val else 0 end) as NOV.
    sum (case monthname when 'DEC' then Val else 0 end) as DEC
    FROM MyTable
    Group of itemtype
    )
    where (oct = 0 & nov = 0 and dec = 0 and jan = 0 and 0 = Feb and mar = 0
    apr = 0 and may = 0 and = 0 jun and Jul = 0 and aug = 0 and Ms = 0
    )
    order of itemtype
    {code}

    Change again... OK, I guess that I am answering my own question here, but I think that by using a WITH to write the main request once clause and then selecting * twice using the MINUS operator between where the second query is where (oct = 0, etc.) is what I need. If anyone has better suggestions, please let me know! Here's the logic of nickname for what I come up with to date...

    {code}
    WITH mainquery as (select all)
    Select * from mainquery
    less
    Select * from mainquery where (oct = 0, nov = 0, etc...)
    {code}

    Thanks again!
    Mark

    Published by: user455268 on March 1, 2012 19:13

    Published by: user455268 on March 1, 2012 19:16

    Hello

    You can do it with a HAVING clause:

    select
      itemtype,
      sum (case monthname when 'JAN' then theval else 0 end) as JAN,
      sum (case monthname when 'FEB' then theval else 0 end) as FEB,
      sum (case monthname when 'MAR' then theval else 0 end) as MAR,
      sum (case monthname when 'APR' then theval else 0 end) as APR,
      sum (case monthname when 'MAY' then theval else 0 end) as MAY,
      sum (case monthname when 'JUN' then theval else 0 end) as JUN,
      sum (case monthname when 'JUL' then theval else 0 end) as JUL,
      sum (case monthname when 'AUG' then theval else 0 end) as AUG,
      sum (case monthname when 'SEP' then theval else 0 end) as SEP,
      sum (case monthname when 'OCT' then theval else 0 end) as OCT,
      sum (case monthname when 'NOV' then theval else 0 end) as NOV,
      sum (case monthname when 'DEC' then theval else 0 end) as DEC
    from mytable
    group by itemtype
    HAVING      MIN (theval)     != 0
    OR      MAX (theval)     != 0
    order by itemtype
    ;
    

    If the values are all 0, then the MIN and MAX will be 0.
    If the MIN or MAX is not 0, the values are all 0.

    This assumes that the combination (itemtype, monthname) is unique, because it is in your sample data.
    If this is not the case, start with a subquery that GROUPs BY itemtype, monthname, so that when you get to the main request, this combination will be unique.

  • How to get the sum by customer?

    Hi, in this query below, I want all the s () basically summing up of each "INVESTOR_CODE", can anyone help please?
    select 
    b.INVESTOR_CODE ,
    a.INVESTOR_NAME , 
    b.DEPARTMENT_CODE , 
    b.INVOICE_NO , 
    b.INVOICE_TYPE , 
    trunc(b.INVOICE_date) INVOICE_date, 
    c.COMPANY_SHORT_NAME , 
    sum(INVOICE_COMMISSION)  INVOICE_COMMISSION, 
    sum(INVOICE_KEEPING)  INVOICE_KEEPING , 
    sum(INVOICE_STAMP)  INVOICE_STAMP, 
    sum(INVOICE_OTHER) INVOICE_OTHER,
    sum(INVOICE_MISR) INVOICE_MISR,
    sum(INVOICE_INSURANCE) INVOICE_INSURANCE,
    sum(INVOICE_HAIAH)INVOICE_HAIAH
    from investor a , invoice b , company c , DEPARTMENT d
    where a.INVESTOR_CODE = b.INVESTOR_CODE
    and b.COMPANY_CODE = c.COMPANY_CODE
    and b.DEPARTMENT_CODE  = d.DEPARTMENT_CODE
    and trunc(invoice_date) >= '14-AUG-07'
    exists(select 1 from OPERATION_LINE_SMAEDAY ols where ols.INVOICE_NO  = b.INVOICE_NO and ols.INVOICE_type  = b.INVOICE_type  )
    group by  b.INVESTOR_CODE , a.INVESTOR_NAME , b.DEPARTMENT_CODE , b.INVOICE_NO , b.INVOICE_TYPE , trunc(b.INVOICE_date) , b.INVOICE_TYPE,c.COMPANY_SHORT_NAME
    order by b.INVESTOR_CODE  , INVOICE_date;

    For this table, the following query will do the grouping and order it as you want. You will still combine it with the previous query using the original paintings.

    SQL> select investor_code
      2       , investor_name
      3       , department_code
      4       , invoice_no
      5       , invoice_type
      6       , invoice_date
      7       , company_short_name
      8       , sum(invoice_commission)
      9       , sum(invoice_keeping)
     10       , sum(invoice_stamp)
     11       , sum(invoice_other)
     12       , sum(invoice_misr)
     13       , sum(invoice_insurance)
     14       , sum(invoice_haiah)
     15    from samedaydata
     16   group by investor_code
     17       , investor_name
     18       , rollup
     19         ( ( department_code
     20           , invoice_no
     21           , invoice_type
     22           , invoice_date
     23           , company_short_name
     24           )
     25         )
     26   order by investor_code
     27       , department_code
     28       , invoice_no
     29  /
    
    INVESTOR_CODE INVESTOR_NAME   DEPARTMENT_CODE INVOICE_NO INVOIC INVOICE_DATE        COMPANY_SHORT_NAME   SUM(INVOICE_COMMISSION)
    ------------- --------------- --------------- ---------- ------ ------------------- -------------------- -----------------------
    SUM(INVOICE_KEEPING) SUM(INVOICE_STAMP) SUM(INVOICE_OTHER) SUM(INVOICE_MISR) SUM(INVOICE_INSURANCE) SUM(INVOICE_HAIAH)
    -------------------- ------------------ ------------------ ----------------- ---------------------- ------------------
           240007 john                          2        123 sell   23-04-2010 00:00:00 OTC                                     27.5
                     3.4                  6                  4                 0                      2                 10
    
           240007 john                          2        124 buy    22-04-2010 00:00:00 ORACLE                                  29.6
                     2.4                  6                  4                 0                      2                 10
    
           240007 john                          2        125 sell   01-01-2010 00:00:00 ORACLE                                  63.5
                     2.4                  6                  4                 7                      2                 10
    
           240007 john                                                                                                         120.6
                     8.2                 18                 12                 7                      6                 30
    
           240008 paul                          3        256 sell   19-12-2010 00:00:00 OTC                                     93.5
                     8.4                  6                  4                 0                      2                 10
    
           240008 paul                          3        266 buy    06-03-2010 00:00:00 CBANK                                   83.2
                     3.4                  6                  3                 0                      2                  9
    
           240008 paul                          3        322 buy    23-04-2010 00:00:00 CBANK                                   43.4
                     2.4                  3                  4                 0                      2                  3
    
           240008 paul                          3        423 sell   23-04-2010 00:00:00 OTT                                     24.5
                     2.4                  2                  4                 0                      8                 10
    
           240008 paul                                                                                                         244.6
                    16.6                 17                 15                 0                     14                 32
    
    9 rows selected.
    

    Kind regards
    Rob.

  • Get the sum of the variable lines (number of lines is unknown)

    Dear all,

    I need to create a script with the option for the raws of addidional (Dezimalfelde2 + Dezimalfelde3 +...), the total amount should include all future raws...

    How can I create it? Please see above the javascript below... I tried to write (Dezimalfelde2) [*] just to indicate all the lines of smart but his does not work!

    Please help ?

    1.png

    Moin,

    the accessor is placed in the wrong place.

    There is that a single "Dezimalfeld2" in each line you don't need the accessor [*] here.

    But the line 'detail' repeats itself, so this is the place where you should use.

    var total = 0;
    var fields = xfa.resolveNodes("Tabelle4.detail[*].Dezimalfeld2");
    
    for (var i = 0; i < fields.length; i += 1) {
        total += parseInt(fields.item(i).rawValue);
    }
    this.rawValue = total;
    
  • need to get the sum of the two attribute

    Hello.

    I use jdev 11.1.1.5

    In this, I had a tptrialbal of the table in which the values are inserted by using the given code
                        Row vor = vo.createRow();
                        vor.setAttribute("TtrbDesc1",row1.getAttribute("GaclDesc1"));
                        vor.setAttribute("TtrbDebitAmt",row1.getAttribute("SumGapbDebitAmt"));
                        vor.setAttribute("TtrbCreditAmt",row1.getAttribute("SumGapbCreditAmt"));
    //                 For an attribute ttrbAmt = TtrbDebitAmt+TtrbCreditAmt;
    How can I dot this., can someone help me pls

    Try this

    Integer ttrbAmt = Integer.parseInt(row1.getAttribute("SumGapbDebitAmt").toString())    + Integer.parseInt(row1.getAttribute("SumGapbCreditAmt").toString());
    
  • to get the amount in function hrov.name only

    Hi all


    I have the following query with me

    SELECT DISTINCT rvt.receipt_num srv_no, rvt.supplier supplier,
                    rvt.transaction_date srv_date, inv.segment1 item_no,
                    rvt.item_desc item_description, hrov.NAME,
                    
                    (   SUBSTR (v.standard_industry_class, 1, 1)
                     || '-'
                     || po_headers.segment1
                     || '-'
                     || TO_CHAR (po_headers.creation_date, 'RRRR')
                    ) po_no,
                    po_headers.creation_date_disp po_date,
                   
                    (  (rvt.currency_conversion_rate * po_lines.unit_price)
                     * rvt.transact_qty
                    )aMOUNT  ,
           
                          (SELECT SUM (mot.on_hand)
                       FROM mtl_onhand_total_mwb_v mot
                      WHERE inv.inventory_item_id = mot.inventory_item_id
                        --  AND INV.ORGANIZATION_ID=MOT.ORGANIZATION_ID
                        AND loc.inventory_location_id = mot.locator_id
                        AND loc.organization_id = mot.organization_id
                        AND rvt.locator_id = mot.locator_id) onhand
               FROM rcv_vrc_txs_v rvt,
                    mtl_system_items_b inv,
                    mtl_item_locations loc,
                    hr_organization_units_v hrov,
                    po_headers_v po_headers,
                    ap_vendors_v v,
                    po_lines_v po_lines
              WHERE inv.inventory_item_id(+) = rvt.item_id
                AND po_headers.vendor_id = v.vendor_id
                AND rvt.po_line_id = po_lines.po_line_id
                AND rvt.po_header_id = po_lines.po_header_id
                AND rvt.po_header_id = po_headers.po_header_id
                AND rvt.supplier_id = v.vendor_id
                AND inv.organization_id = hrov.organization_id
                AND rvt.transaction_type = 'DELIVER'
                AND rvt.inspection_status_code <> 'REJECTED'
                AND rvt.organization_id = inv.organization_id(+)
                AND TRUNC (rvt.transaction_date) BETWEEN (:p_from_date)
                                                     AND NVL (:p_to_date,
                                                              :p_from_date
                                                             )
                AND rvt.locator_id = loc.physical_location_id(+)
                AND transaction_id NOT IN (
                       SELECT parent_transaction_id
                         FROM rcv_vrc_txs_v rvtd
                        WHERE rvt.item_id = rvtd.item_id
                          AND rvtd.transaction_type IN
                                      ('RETURN TO RECEIVING', 'RETURN TO VENDOR'))
                                             
                   
    
    i require sum of  amount based on  hrov.name (organization name ) only 
    i tried doing sum of amount(sum_amount) but i am not able to get the sum based on the organization "other inventory items'
    
    SELECT DISTINCT rvt.receipt_num srv_no, rvt.supplier supplier,
                    rvt.transaction_date srv_date, inv.segment1 item_no,
                    rvt.item_desc item_description, hrov.NAME,
                    
                    (   SUBSTR (v.standard_industry_class, 1, 1)
                     || '-'
                     || po_headers.segment1
                     || '-'
                     || TO_CHAR (po_headers.creation_date, 'RRRR')
                    ) po_no,
                    po_headers.creation_date_disp po_date,
                   
                  
            SUM(          (  (rvt.currency_conversion_rate * po_lines.unit_price)
                     * rvt.transact_qty))SUM_AMOUNT,
                                                       
                     
                    
                    (SELECT SUM (mot.on_hand)
                       FROM mtl_onhand_total_mwb_v mot
                      WHERE inv.inventory_item_id = mot.inventory_item_id
                        --  AND INV.ORGANIZATION_ID=MOT.ORGANIZATION_ID
                        AND loc.inventory_location_id = mot.locator_id
                        AND loc.organization_id = mot.organization_id
                        AND rvt.locator_id = mot.locator_id) onhand
               FROM rcv_vrc_txs_v rvt,
                    mtl_system_items_b inv,
                    mtl_item_locations loc,
                    hr_organization_units_v hrov,
                    po_headers_v po_headers,
                    ap_vendors_v v,
                    po_lines_v po_lines
              WHERE inv.inventory_item_id(+) = rvt.item_id
                AND po_headers.vendor_id = v.vendor_id
                AND rvt.po_line_id = po_lines.po_line_id
                AND rvt.po_header_id = po_lines.po_header_id
                AND rvt.po_header_id = po_headers.po_header_id
                AND rvt.supplier_id = v.vendor_id
                AND inv.organization_id = hrov.organization_id
                AND rvt.transaction_type = 'DELIVER'
                AND rvt.inspection_status_code <> 'REJECTED'
                AND rvt.organization_id = inv.organization_id(+)
                AND TRUNC (rvt.transaction_date) BETWEEN (:p_from_date)
                                                     AND NVL (:p_to_date,
                                                              :p_from_date
                                                             )
                AND rvt.locator_id = loc.physical_location_id(+)
                AND transaction_id NOT IN (
                       SELECT parent_transaction_id
                         FROM rcv_vrc_txs_v rvtd
                        WHERE rvt.item_id = rvtd.item_id
                          AND rvtd.transaction_type IN
                                      ('RETURN TO RECEIVING', 'RETURN TO VENDOR'))
                                             
                                              GROUP BY rvt.receipt_num , rvt.supplier ,
                    rvt.transaction_date , inv.segment1 ,
                    rvt.item_desc , hrov.NAME,v.standard_industry_clasS,po_headers.segment1,po_headers.creation_datE,
                        po_headers.creation_date_disp,inv.inventory_item_iD,loc.inventory_location_id,loc.organization_id,
                        rvt.locator_iD
    
    presently this is how the output looks like inspite of taking sum
    SUM_AMOUNT             NAME
      
     
    275.00                 OTHER INVENTORY ITEMS        
    3.60                    OTHER INVENTORY ITEMS
    35.25                  OTHER INVENTORY ITEMS
    335.00                 ASSET ORGANIZATION
    25.00                   ASSET ORGANIZATION
    7.00                    ASSET ORGANIZATION
    7.00                    ASSET ORGANIZATION
    
     the output should be coming like this
    
    sum_amount           NAME
    313.85                 OTHER INVENTORY ITEMS
    374                      ASSET ORGANIZATION
    kindly guide me
    thanking in advance

    Published by: makdutakdu on March 25, 2012 08:08

    Published by: makdutakdu on March 25, 2012 08:16

    Still not clear...

    You need all the other details that it is, and sum_amount, grouped by hrov.name?

    You can use the analytic function...

    SELECT rvt.receipt_num srv_no, rvt.supplier supplier,
                    rvt.transaction_date srv_date, inv.segment1 item_no,
                    rvt.item_desc item_description, hrov.NAME,
                    (   SUBSTR (v.standard_industry_class, 1, 1)
                     || '-'
                     || po_headers.segment1
                     || '-'
                     || TO_CHAR (po_headers.creation_date, 'RRRR')
                    ) po_no,
                    po_headers.creation_date_disp po_date,
    ----Analytic function used here
            SUM(          (  (rvt.currency_conversion_rate * po_lines.unit_price)
                     * rvt.transact_qty)) over(partition by hrov.NAME) SUM_AMOUNT,
                    (SELECT SUM (mot.on_hand)
                       FROM mtl_onhand_total_mwb_v mot
                      WHERE inv.inventory_item_id = mot.inventory_item_id
                        --  AND INV.ORGANIZATION_ID=MOT.ORGANIZATION_ID
                        AND loc.inventory_location_id = mot.locator_id
                        AND loc.organization_id = mot.organization_id
                        AND rvt.locator_id = mot.locator_id) onhand
               FROM rcv_vrc_txs_v rvt,
                    mtl_system_items_b inv,
                    mtl_item_locations loc,
                    hr_organization_units_v hrov,
                    po_headers_v po_headers,
                    ap_vendors_v v,
                    po_lines_v po_lines
              WHERE inv.inventory_item_id(+) = rvt.item_id
                AND po_headers.vendor_id = v.vendor_id
                AND rvt.po_line_id = po_lines.po_line_id
                AND rvt.po_header_id = po_lines.po_header_id
                AND rvt.po_header_id = po_headers.po_header_id
                AND rvt.supplier_id = v.vendor_id
                AND inv.organization_id = hrov.organization_id
                AND rvt.transaction_type = 'DELIVER'
                AND rvt.inspection_status_code  'REJECTED'
                AND rvt.organization_id = inv.organization_id(+)
                AND TRUNC (rvt.transaction_date) BETWEEN (:p_from_date)
                                                     AND NVL (:p_to_date,
                                                              :p_from_date
                                                             )
                AND rvt.locator_id = loc.physical_location_id(+)
                AND transaction_id NOT IN (
                       SELECT parent_transaction_id
                         FROM rcv_vrc_txs_v rvtd
                        WHERE rvt.item_id = rvtd.item_id
                          AND rvtd.transaction_type IN
                                      ('RETURN TO RECEIVING', 'RETURN TO VENDOR'))
    
                                      GROUP BY rvt.receipt_num , rvt.supplier ,
                    rvt.transaction_date , inv.segment1 ,
                    rvt.item_desc , hrov.NAME,v.standard_industry_clasS,po_headers.segment1,po_headers.creation_datE,
                    po_headers.creation_date_disp,inv.inventory_item_iD,loc.inventory_location_id,loc.organization_id,
                    rvt.locator_iD
    
  • How can I get the amount of a particular attribute of an entity

    Hello

    I'm quite new to JDeveloper and ADF, and I have a lot of problems with a simple question.

    I am writing an application using JSF, and ADF BC (JDeveloper 10.1.3.4).
    I have two entities, joined in relationship master / detail. My JSP page print the main view in read-only mode, the view in read/write mode.
    Each view has an attribute, I call it IMPORT. The sum of all the IMPORT attribute in the detail records must match the IMPORT attribute in the master. Without this condition, the user may not engage.

    I don't really know how to solve this apparently simple question.
    I think in the right place is the validateEntity in the EntityImpl, but how do I circle on all records to get the sum of "import" attributes to match the attribute "import" in the body of my master?

    Thanks to all in advance

    Mariella

    PS. Sorry for my bad English

    You can use an association between the two OS for an accessor to navigate the relationship between knowledge of the two OS the sum of all the IMPORTS for a specific master and compare it to the IMPORTATION of master.
    More details here:
    http://download.Oracle.com/docs/HTML/B25947_01/bcentities008.htm#sthref464
    and here:
    http://download.Oracle.com/docs/HTML/B25947_01/bcentities003.htm#sm0133

Maybe you are looking for