Help me Join 2 separate queries

SQL> select op_date, sum(withdrawal) withdrawal, sum(deposit) deposit from (
  2  select op_date_frm op_date, null withdrawal, op_amount deposit
  3  from op_bal
  4  union all
  5  select op_date_frm op_date,sum(DECODE(EXPN_EI,'E',EXN_AMOUNT)) WITHDRAWAL,
  6  sum(DECODE(EXPN_EI,'I',EXN_AMOUNT)) DEPOSIT
  7  from EXPENSES_TXN, expense_master
  8  where exn_acnt_code = expn_code
  9  and exn_date < to_date('01/04/2009','dd/mm/yyyy'))
10  group by op_date
11  /
OP_DATE                             WITHDRAWAL       DEPOSIT
01-APR-09                             2045.000      6200.000
SQL> SELECT OP_DATE,TNO,OP_CODE,EI,WITHDRAWAL,DEPOSIT,
  2  sum(NVL(DEPOSIT,0)-NVL(WITHDRAWAL,0)) over (order by op_date,tno) bal
  3  FROM (SELECT OP_DATE,NULL TNO,OP_CODE,NULL EI,NULL WITHDRAWAL,OP_AMOUNT DEPOSIT
  4  FROM OP_BAL
  5  UNION ALL
  6  SELECT
  7  EXN_DATE,
  8  EXN_NO,
  9  EXN_ACNT_CODE,
10  EXPN_EI,
11  DECODE(EXPN_EI,'E',EXN_AMOUNT) WITHDRAWAL,
12  DECODE(EXPN_EI,'I',EXN_AMOUNT) DEPOSIT
13  FROM EXPENSES_TXN, EXPENSE_MASTER
14  WHERE EXN_ACNT_CODE = EXPN_CODE
15  order by 1) a
16  WHERE OP_DATE  between to_date('01/04/2009','dd/mm/yyyy') and to_date('30/4/2009','dd/mm/yyyy')
17  order by op_date
18  /
OP_DATE             TNO OP_COD E    WITHDRAWAL       DEPOSIT           BAL
01-APR-09         9.000 AC0013 I                     250.000       250.000
07-APR-09         1.000 AC0001 E       200.000                      50.000
09-APR-09         3.000 AC0003 E        50.000                        .000
09-APR-09         4.000 AC0011 E        35.000                     -35.000
should give me this result;
OP_DATE             TNO OP_COD E    WITHDRAWAL       DEPOSIT           BAL
01-APR-09               OP0000        2045.000      6200.000      4155.000
01-APR-09         9.000 AC0013 I                     250.000      4405.000
07-APR-09         1.000 AC0001 E       200.000                    4205.000
09-APR-09         4.000 AC0011 E        35.000                    4170.000
09-APR-09         3.000 AC0003 E        50.000                    4120.000

i nearly solved it, stuck at order by,,please help
select rownum rn, op_date, TNO,OP_CODE,EI,withdrawal,deposit,
sum(NVL(DEPOSIT,0)-NVL(WITHDRAWAL,0)) over (order by op_date,tno) bal
from
select op_date, NULL TNO,null OP_CODE,NULL EI,withdrawal,deposit
from
select to_date('01/04/2009','dd/mm/yyyy') op_date, sum(withdrawal) withdrawal, sum(deposit) deposit
from
select op_date, null withdrawal, op_amount deposit
from op_bal
union all
select to_date('01/04/2009','dd/mm/yyyy') op_date,sum(DECODE(EXPN_EI,'E',EXN_AMOUNT)) WITHDRAWAL,
sum(DECODE(EXPN_EI,'I',EXN_AMOUNT)) DEPOSIT
from EXPENSES_TXN, expense_master
where exn_acnt_code = expn_code
and exn_date < to_date('01/04/2009','dd/mm/yyyy'))
union all
SELECT
EXN_DATE,
EXN_NO,
EXN_ACNT_CODE,
EXPN_EI,
DECODE(EXPN_EI,'E',EXN_AMOUNT) WITHDRAWAL,
DECODE(EXPN_EI,'I',EXN_AMOUNT) DEPOSIT
FROM EXPENSES_TXN, EXPENSE_MASTER
WHERE EXN_ACNT_CODE = EXPN_CODE
and EXN_DATE between to_date('01/04/2009','dd/mm/yyyy') and to_date('30/4/2009','dd/mm/yyyy'))
order by op_date,rn
           RN OP_DATE             TNO OP_COD E    WITHDRAWAL       DEPOSIT           BAL
        1.000 01-APR-09                             2045.000      6200.000      4405.000   <<----NOT doing Summ properly
        5.000 01-APR-09         9.000 AC0013 I                     250.000       250.000
        2.000 07-APR-09         1.000 AC0001 E       200.000                    4205.000
        3.000 09-APR-09         3.000 AC0003 E        50.000                    4155.000
        4.000 09-APR-09         4.000 AC0011 E        35.000                    4120.000
earlier with another query i got this result;
select op_date, TNO,OP_CODE,EI,withdrawal,deposit,
sum(NVL(DEPOSIT,0)-NVL(WITHDRAWAL,0)) over (order by op_date) bal
from
select op_date, NULL TNO,null OP_CODE,NULL EI,withdrawal,deposit
from
select to_date('01/04/2009','dd/mm/yyyy') op_date, sum(withdrawal) withdrawal, sum(deposit) deposit
from
select to_date('01/04/2009','dd/mm/yyyy') op_date,sum(DECODE(EXPN_EI,'E',EXN_AMOUNT)) WITHDRAWAL,
sum(DECODE(EXPN_EI,'I',EXN_AMOUNT)) DEPOSIT
from EXPENSES_TXN, expense_master
where exn_acnt_code = expn_code
and exn_date < to_date('01/04/2009','dd/mm/yyyy')
union all
select op_date, null withdrawal, op_amount deposit
from op_bal))
union all
SELECT
EXN_DATE,
EXN_NO,
EXN_ACNT_CODE,
EXPN_EI,
DECODE(EXPN_EI,'E',EXN_AMOUNT) WITHDRAWAL,
DECODE(EXPN_EI,'I',EXN_AMOUNT) DEPOSIT
FROM EXPENSES_TXN, EXPENSE_MASTER
WHERE EXN_ACNT_CODE = EXPN_CODE
and EXN_DATE between to_date('01/04/2009','dd/mm/yyyy') and to_date('30/4/2009','dd/mm/yyyy'))
order by op_DATE
OP_DATE             TNO OP_COD E    WITHDRAWAL       DEPOSIT           BAL
01-APR-09                             2045.000      6200.000      4405.000
01-APR-09         9.000 AC0013 I                     250.000      4405.000
07-APR-09         1.000 AC0001 E       200.000                    4205.000
09-APR-09         4.000 AC0011 E        35.000                    4120.000     <<---- tno 4 should be after 3
09-APR-09         3.000 AC0003 E        50.000                    4120.000

Similar Messages

  • HELP - Query Join Problem

    I am trying to write a query to return data from 4 different tables and it is doubling my summed values. I can get the separate queries to work, but not combined and I need them combined so that I can get a balance due and limit the records to only those that had a total billed (fees) less than $200.
    Query #1 Gets the total of the fees due for each appeal type and invoice:
    Note: There is always at least one fee attached to an invoice.
    SELECT APT.APTY_DESCR "APPEAL TYPE",
    INV.INVC_ID_SEQ INVOICE,
    SUM( ALL FEE.AMT_DUE) "TOTAL BILLED AMOUNT"
    FROM WRD_APPEALS AP,
    WRD_INVOICES INV,
    WRD_FEES_DUE FEE,
    WRD_APPEAL_TYPES APT
    WHERE AP.APST_CD = 'PEND'
    AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
    AND AP.INVC_ID_SEQ = FEE.INVC_ID_SEQ
    AND AP.APTY_CD = APT.APTY_CD
    GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
    ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ
    4     BILLING CATEGORY INCORRECT     4147     1200
    5     BILLING CATEGORY INCORRECT     4203     1100
    6     BILLING CATEGORY INCORRECT     4216     72600
    7     BILLING CATEGORY INCORRECT     4826     1000
    8     BILLING CATEGORY INCORRECT     4951     2060
    Query #2 Gets the total amount paid for each appeal type and invoice:
    Note: An invoice may or may not have a payment, thus the outer join.
    SELECT APT.APTY_DESCR "APPEAL TYPE",
    INV.INVC_ID_SEQ INVOICE,
    SUM(ALL PMT.PAID_AMT) "AMOUNT PAID"
    FROM WRD_APPEALS AP,
    WRD_INVOICES INV,
    WRD_APPEAL_TYPES APT,
    WRD_PAYMENTS PMT
    WHERE AP.APST_CD = 'PEND'
    AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
    AND AP.APTY_CD = APT.APTY_CD
    AND INV.INVC_ID_SEQ = PMT.INVC_ID_SEQ(+)
    GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
    ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ
    4     BILLING CATEGORY INCORRECT     4147     200
    5     BILLING CATEGORY INCORRECT     4203     0
    6     BILLING CATEGORY INCORRECT     4216     72600
    7     BILLING CATEGORY INCORRECT     4826     
    8     BILLING CATEGORY INCORRECT     4951     
    Combined Query - Gets all of the above as well as the balance due. Note the doubled values for some records.
    SELECT APT.APTY_DESCR "APPEAL TYPE",
    INV.INVC_ID_SEQ INVOICE,
    SUM( ALL FEE.AMT_DUE) "TOTAL BILLED AMOUNT",
         SUM(ALL PMT.PAID_AMT) "AMOUNT PAID",
         (SUM(ALL FEE.AMT_DUE) -
         NVL2(SUM(ALL PMT.PAID_AMT), SUM(ALL PMT.PAID_AMT), 0)) "BALANCE DUE"
    FROM WRD_APPEALS AP,
    WRD_INVOICES INV,
    WRD_FEES_DUE FEE,
    WRD_APPEAL_TYPES APT,
         WRD_PAYMENTS PMT
    WHERE AP.APST_CD = 'PEND'
    AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
         AND INV.INVC_ID_SEQ = PMT.INVC_ID_SEQ(+)
         AND INV.INVC_ID_SEQ = FEE.INVC_ID_SEQ
         AND AP.APTY_CD = APT.APTY_CD
    GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
    ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ,
    4     BILLING CATEGORY INCORRECT     4147     1200     400     800
    5     BILLING CATEGORY INCORRECT     4203     2200     0     2200
    6     BILLING CATEGORY INCORRECT     4216     72600     435600     -363000
    7     BILLING CATEGORY INCORRECT     4826     1000          1000
    8     BILLING CATEGORY INCORRECT     4951     2060          2060
    HELP PLEASE!
    Thank you.

    When you have multiple child rows, the parent row gets returned once for each child row found. Therefore, if you have summed the invoice, it gets summed again for each payment. Perhaps this little example will help you understand the problem.
    Note that I used a sub query here to obtain the desired results. Analytic functions can do the same I believe, but I am still learning them :-)
      D> DROP TABLE DMILL.invoice;
    Table dropped.
      D>
      D> DROP TABLE DMILL.payments;
    Table dropped.
      D>
      D> CREATE TABLE invoice AS
         SELECT 1 id, 10 amount FROM DUAL UNION ALL
         SELECT 2 id, 10  FROM DUAL UNION ALL
         SELECT 2 id, 10  FROM DUAL UNION ALL
         SELECT 3 id, 10  FROM DUAL;
    Table created.
      D>
      D> CREATE TABLE payments AS
         SELECT 1 inv_id, 5 amount FROM DUAL UNION ALL
         SELECT 1 inv_id, 5 amount FROM DUAL UNION ALL
         SELECT 2 inv_id, 5 amount FROM DUAL UNION ALL
         SELECT 2 inv_id, 5 amount FROM DUAL UNION ALL
         SELECT 2 inv_id, 5 amount FROM DUAL;
    Table created.
      D>
      D> select * from invoice;
            ID     AMOUNT
             1         10
             2         10
             2         10
             3         10
      D>
      D> select * from payments;
        INV_ID     AMOUNT
             1          5
             1          5
             2          5
             2          5
             2          5
      D>
      D> select id
                  ,sum (amount)
          from  invoice
         group by id;
            ID SUM(AMOUNT)
             1          10
             2          20
             3          10
      D>
      D> select inv_id
                  ,sum(amount)
          from  payments
         group by inv_id;
        INV_ID SUM(AMOUNT)
             1          10
             2          15
      D>
      D> select inv.id
                  ,inv.amount
                  ,pay.amount
          from invoice  inv
                 ,payments pay
         where pay.inv_id = inv.id;
            ID     AMOUNT     AMOUNT
             1         10          5
             1         10          5
             2         10          5
             2         10          5
             2         10          5
             2         10          5
             2         10          5
             2         10          5
    8 rows selected.
      D>
      D> select inv.id
                  ,sum(inv.amount)
                  ,sum(pay.amount)
          from invoice  inv
                 ,payments pay
         where pay.inv_id = inv.id
         group by inv.id;
            ID SUM(INV.AMOUNT) SUM(PAY.AMOUNT)
             1              20              10
             2              60              30
      D>
      D> select inv.id
                  ,sum(inv.amount)
                  ,(SELECT sum(pay.amount)
                    FROM   payments pay
                    WHERE  pay.inv_id = inv.id)
          from invoice  inv
         group by inv.id;
            ID SUM(INV.AMOUNT) (SELECTSUM(PAY.AMOUNT)FROMPAYMENTSPAYWHEREPAY.INV_ID=INV.ID)
             1              10                                                           10
             2              20                                                           15
             3              10Let me know if you need further explanation.

  • OBIEE: Link Two Separate Queries Together

    Hi,
    I am trying to link two separate queries together in BIEE.
    I have a query that will give me the sales value in January 2012 (monthly query)
    But I would need to use the sales value of January 2012 to help derive the weekly sales value in another query (weekly query).
    How would you link up two queries together?
    I tried using union but it doesnt seem to be working.
    Thanks.
    Bill

    Hi Billy,
    Sure, My pleasure. Here are the basic steps what you could go through.
    1. Create an analysis with your Month (January) and Sales.
    2. Save this analysis as Report1.
    3. Create another analysis with Week and Sales.
    4. Create a filter on column:Sales using the option 'Based on Another Analysis'. The analysis editor will provide you an option to browse your other analysis which you want this analysis to be based on and just click on this browse button, and navigate to and select Report1.
    5. Once you have selected Report 1 through browse option, you get down in the same pop-up the relationship and use values in column.
    So sample entries in this pop-up might look like
    Column : Sales
    Operator : is based on results of another analysis
    Saved Analysis : /My Folder/Report1
    Relationship : is equal than
    Use values in Column : Sales
    6. If you run this analysis, you could get all weekly sales figures which are equal to the january sales figures.
    Hope this helps.
    Thank you,
    Dhar

  • Self join vs Hierarchical Queries

    Hi,
    please tel me which one 1 should use ?
    i have to get simple manger's employ list, should i use self join or hierarchical queries(CONNECT BY and prior)?
    yours sincerely

    Hi,
    944768 wrote:
    Hi,
    please tel me which one 1 should use ?
    i have to get simple manger's employ list, should i use self join or hierarchical queries(CONNECT BY and prior)?It depends on your data and your requirements.
    Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements) for all the tables involved, so the people who want to help you can re-create the problem and test their ideas. Also post the results you want from that data, and an explanation of how you get those results from that data.
    Explain, using specific examples, how you get those results from that data.
    If you can show what the problem is using commonly available tables (suc as scott.emp, which has a 4-level hierarchy) then you don't have ot post any sample data, just the results and the explanation.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    If your hierarchy consists only of 2 levels, then a self-join will probably be more efficient, simpler to code, and easier to maintain.
    If you don't know how many levels are in the hierarchy, then self-join isn't an option. Use CONNECT BY or, if you have Oracle 11.2, a recursive WITH clause.
    If you have a fixed number of levels (or an upper bound) greater than 2, then CONNECT BY (or a recursive WITH clause) will probably be best.

  • QUESTION:  In Elements 12, how do I join together separate slideshows into a single integrated alideshow?

    QUESTION:  In Elements 12, how do I join together separate slideshows into a single integrated alideshow?

    I hate to say this, but there is no way to put 1280X720 footage on a 1920X1080 sequence and upscale it to match the frame size without losing some quality. Basically, you are asking Premiere Pro to provide new pixels that were not in the original video. That is seldom a really good idea. You might want to try investing in program designed to upscale video. I have never used this, but there is a free trial, so give it a shot: http://www.infognition.com/VideoEnhancer/
    Of course, it all depends on the content. Try it with Premiere Pro. Only you can judge. However, you might need to consider putting all of your 1920X1080 on a 1280X720 sequence instead, and just produce your video at that size.
    Or, once again, this depends on the content, put some sort of frame around the smaller footage, either a blurred out version of the upscaled footage - lots of TV stations do this with 4:3 footage on a HD program, or purposefully make it even a little smaller, or crop it, and use parts of the same video in Picture-In-Picture. You have seen this before. A person talking on the phone in a larger frame to the left, and on the right a closeup of the mouth, or maybe a clip of the person they are talking to. Or use some B-Roll in the PiP.
    Get imaginative, because you already know that you messed up, so perhaps make it look like you did it on purpose.

  • HT4623 How can I join 2 separate account one for my IPhone and one to my IPad to one account with the same ID and Password?

    How can I join 2 separate account one for my IPhone and one to my IPad to one account with the same ID and Password?

    You cannot combine two different Apple ID's into one ID.

  • Two separate queries in one report

    Hi Gurus,
    Is it possible to make two separate queries in the same worksheet (I need to have a column in my report from a different query from this report). As we can have more than one query in Oracle Reports, similarly, is it possible to have more than one query in Oracle Discoverer Report.
    Thanks,
    Pooja

    The functionality your looking for is not available in Discoverer today. You can have two separate worksheets within Discoverer, one to run each query. Another option is only available in Discoverer Desktop, it is called a subquery which allows you to run one query and then pass the results as a parameter into your workbook. However, I don't believe either of those options resolve the problem your looking to solve.
    Matt Topper
    TUSC, The Oracle Experts
    [email protected]

  • Please sugges the link helpful for writing efficient sql queries

    Please suggest any good resource that is weblink which can help me in optimizing sql queries. especially while writing select statements improve the execution time of the sql query.
    Thanx in advance
    prasanth

    in general I found books from O'Reilly very helpful (not only for Oracle, but for Unix too).
    Moreover there is pretty good Oracle Documentation available.
    After all, it's not only about writing good queries, but also about setting up data-models, indexes, primary keys, etc.
    Look for a real slow computer, take a lot of data, then try writing your speedy queries. This is the school of hard knocks, on the long run it's the best training.

  • Help with Joining a few tables

    I need a help using JOINS. I plan to create ONE VIEW by bringing in all fields from First and Second table and a few chosen columns from Third, Fourth and Fifth tables. I have put to together below select statement which appears to be working syntax-wise but not efficient and may have dupes.
    Table1 - RPT_APRL_PRODUCT with key field KEY_MATERIAL (KEY_MATERIAL = DIVISION||PLAN_CTRY||MKT_TYP_ID||MATERIAL)
    Table 2 - RPT_FWEQ_PRODUCT with key field KEY_MATERIAL (KEY_MATERIAL = DIVISION||PLAN_CTRY||MATERIAL)
    Table 3 - NSC_PROD_CIMG has a Key Field = MATERIAL_NBR
    Table 4- STAGE#EMEA_NSAP.NSC_PROD_REG_CIMG has the Key field MATERIAL_NBR, REG_ID
    Table 5 - STAGE#EMEA_NSAP.NSC_PROD_REG_CYC_CIMG has Key Fields MATERIAL_NBR, REG_ID, CYC_ID and ORGVERSIONID
    Columns needed from Table 3 -- B.DIVISION, B.DIVISIONNAME, B.SUBLABEL, B.SUBLABELNAME and B.DEVELOPMENTREGION.
    Columns needed from Table 4 --- C.GLOBALSOURCEINDICATOR
    Columns needed from Table 5--- D.CARRYOVERFLAG
    SELECT statement:
    SELECT /*+ parallel (a,5) parallel (NET,5) */
    a.key_material,
    a.mkt_typ_id,
    a.region_id,
    CASE
    WHEN a.region_id = '3' THEN 'USA'
    WHEN a.region_id = '4' THEN 'EMEA'
    WHEN a.region_id = '7' THEN 'CANADA'
    END AS region_desc,
    a.mkt_reg_cd,
    CASE
    WHEN a.mkt_reg_cd = '01' THEN 'USA'
    WHEN a.mkt_reg_cd = '02' THEN 'EMEA'
    WHEN a.mkt_reg_cd = '05' THEN 'AMER'
    END AS mkt_reg_desc,
    a.cat_bus_cd1,
    a.cat_bus_desc1,
    a.cat_bus_cd2,
    a.cat_bus_desc2,
    a.cat_bus_cd3,
    a.cat_bus_desc3,
    a.cat_bus_cd4,
    a.cat_bus_desc4,
    a.mkstr_cd,
    a.mkt_clsfn_desc,
    a.mkt_clsfn_cd1,
    a.mkt_clsfn1_desc,
    a.mkt_clsfn_cd2,
    a.mkt_clsfn2_desc,
    a.mkt_clsfn_cd3,
    a.mkt_clsfn3_desc,
    a.exp_sty_ind,
    a.silh_cd,
    a.silh_desc,
    a.whlsl_prc,
    0,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    a.gender_age_class_id,
    a.gender_age_desc,
    a.sports_activity_class_id,
    a.sports_act_cls_desc,
    a.gblcatsummcode,
    a.gblcatsummdesc,
    a.gblcatcorefocuscode,
    a.gblcatcorefocusdesc,
    a.segment,
    a.segmentname,
    a.l4l_fl,
    NET.DIVISION,
    NET.DIVISIONNAME,
    NET.SUBLABEL,
    NET.SUBLABELNAME,
    NET.DEVELOPMENTREGION,
    NULL,
    NULL,
    NULL,
    NET.globalsourceindicator,
    NET.CARRYOVERFLAG,
    a.zz_chng_tmst,
    a.zz_update_tmst,
    a.zz_insert_tmst
    FROM RPT_APRL_PRODUCT A,
    (SELECT
    APRL.DIVISION||APRL.PLAN_CTRY||APRL.MKT_TYP_ID||APRL.MATERIAL ; AS KEY_MATERIAL,
    B.DIVISION,
    B.DIVISIONNAME,
    B.SUBLABEL,
    B.SUBLABELNAME,
    B.DEVELOPMENTREGION,
    C.GLOBALSOURCEINDICATOR,
    D.CARRYOVERFLAG
    from RPT_APRL_PRODUCTAPRL,
    NSC_PROD_CIMG B,
    NSC_PROD_REG_CIMG C,
    NSC_PROD_REG_CYC_CIMG D
    where APRL.MATERIAL = B.MATERIAL_NBR AND
    APRL.MATERIAL = C.MATERIAL_NBR AND
    APRL.MATERIAL = D.MATERIAL_NBR AND
    C.REG_ID = D.REG_ID) NET
    WHERE A.KEY_MATERIAL = NET.KEY_MATERIAL(+)
    Thanks for help in advance.

    I have 4 tables and these are some sample data for
    RPT_APRL_PRODUCT - Key Field = KEY_MATERIAL (this is a combination of plan_ctry,division,mkt_typ_id and material)
    Sample data
    KEY_MATERIAL          PLAN_CTRY   DIVISION  MKT_TYP_ID              MATERIAL
    10PART1136353-010      PART          10              1                      136353-010
    10AMER1136353-010      AMER          10              1                      136353-010
    10USA1136353-010       USA           10              1                      136353-010
    10CANA1136353-010      CANA          10              1                      136353-010
    10PART1137508-050      PART          10              1                      137508-050
    10AMER1137508-050      AMER          10              1                      137508-050
    10CANA1137508-050      CANA          10              1                      137508-050
    10USA1137508-050       USA           10              1                      137508-050
    10PART1137617-050      PART          10              1                      137617-050
    10AMER1137617-050      AMER          10              1                       137617-050nsc_prod_reg_cimg - keys (material_nbr and reg_id)
    MATERIAL                REG_ID          GLOBALSOURCEINDICATOR
    136353-010      3                                     G
    136353-010      6                                     G
    136353-010      7                                    
    137508-050      3                                    
    137508-050      6                                     G
    137508-050      7                                    
    137508-050      46                                    G
    137617-050      3                                    
    137617-050      6                                    
    137617-050      46                                    nsc_prod_reg_cyc_cimg - key is material_nbr, cyc_id, reg_id and orgversion_id
    MATERIAL_NBR       CYC_ID                    orgversion_id                                reg_ID                CARRYOVERFLAG
    136353-010      101                             1                                          3                             Y       
    136353-010      101                              1                                          6                             Y      
    136353-010      101                               1                                          7                             N      
    137508-050      202                               1                                          3                             Y     
    137508-050      202                               1                                          6                             N       
    137508-050      202                               1                                          7                                    
    137617-050      205                               1                                          3                                    
    137617-050      205                               1                                          6                                    
    185204-402      181                              1                                          8                                    
    185204-402      182                               1                                          8                                     nsc_prod_cimg - key is material_nbr
    MATERIAL_NBR     SUBLABEL     SUBLABELNAME
    136353-010           
    137508-050                GD           Good
    137617-050
    185204-402
    185204-402
    185204-402                BE            Better
    185204-402
    185204-402
    185204-402               CO            Core
    185204-402               BS             BestWhat I intend to do, is to create one view by joining these four tables. The columns key_material, plan_ctry, division and MKT_TYP_ID come from RPT_APRL_PRODUCT. I need to join these tables in such a way that I bring in the other 1 or 2 columns each from the 3 tables as described above. The result should have a unique key_material and have the other column data in the view as well.
    Result should be all the columns described above, something like this below...
    KEY_MATERIAL          PLAN_CTRY   DIVISION  MKT_TYP_ID              MATERIAL      SUBLABELNAME  CARRYover_FL
    10PART1136353-010      PART          10              1                      136353-010
    10AMER1136353-010      AMER          10              1                      136353-010

  • Grus help needed in finding the queries with Cartesian  joins

    Hi
    I have a reporting tool in which users are allowed to put the joins on the views and add some sub queries that produces a Cartesian product. Is there any tool or way that I can stop the execution of those query before it is being executed for example
    Step 1 ) user creates a query
    step2 ) user submits it
    step 3) by any tool or any check if Cartesian join is found the query execution is stopped and notify the user that the query is not good if no problem executes the query.
    I really need help in step 3. I am on 9i release2.
    Any help or suggestions will be highly appreciated.

    I Agree with Gasparotto, you should limit the resource consume.
    You must understand that cartesian join, isn´t always a BAD guy, sometimes you need it.
    If your developers are in trouble with handle the join , think about NATURAL JOIN, may be it helps you
    Regards
    Helio Dias

  • Help with joining two queries

    Hi
    We recently inherited a database and we are re-wrting some queries. The first is
    SELECT gu.GEOGRAPHIC_UNIT_ID, gu.GEOGRAPHIC_UNIT_DESC, aggDataC.DATA as Capacity, aggDataP.DATA as Production
    FROM GEOGRAPHIC_UNIT_RELATIONSHIP gur, GEOGRAPHIC_UNIT
    gu, AGGREGATED_DATA aggDataC, AGGREGATED_DATA aggDataP
    WHERE      gur.PARENT_GEOGRAPHIC_UNIT_ID = :geographicUnitId AND gur.CHILD_GEOGRAPHIC_UNIT_ID = gu.GEOGRAPHIC_UNIT_ID
    AND aggDataC.GEOGRAPHIC_UNIT_ID = gu.GEOGRAPHIC_UNIT_ID
    AND ((:CommodityGroupId IS NULL AND
    aggDataC.COMMODITY_GROUP_ID IS NULL) OR (:CommodityGroupId = aggDataC.COMMODITY_GROUP_ID))
    AND ((:CommodityTypeId IS NULL AND
    aggDataC.COMMODITY_TYPE_ID IS NULL) OR (:CommodityTypeId = aggDataC.COMMODITY_TYPE_ID))
    AND ((:PlantTypeId IS NULL AND aggDataC.PLANT_TYPE_ID
    IS NULL) OR (:PlantTypeId = aggDataC.PLANT_TYPE_ID))
    AND aggDataC.ORGANISATION_ID is NULL
    AND aggDataC.YEAR = :Year
    AND aggDataC.STAT_TYPE_ID = (SELECT stat_type_id FROM
    stat_type WHERE stat_type = 'CAP')
    AND aggDataC.STAT_PERIOD_TYPE_ID = :StatPeriodTypeId
    AND aggDataP.GEOGRAPHIC_UNIT_ID = gu.GEOGRAPHIC_UNIT_ID
    AND ((:CommodityGroupId IS NULL AND
    aggDataP.COMMODITY_GROUP_ID IS NULL) OR (:CommodityGroupId = aggDataP.COMMODITY_GROUP_ID))
    AND ((:CommodityTypeId IS NULL AND
    aggDataP.COMMODITY_TYPE_ID IS NULL) OR (:CommodityTypeId = aggDataP.COMMODITY_TYPE_ID))
    AND ((:PlantTypeId IS NULL AND aggDataP.PLANT_TYPE_ID
    IS NULL) OR (:PlantTypeId = aggDataP.PLANT_TYPE_ID))
    AND aggDataP.ORGANISATION_ID is NULL
    AND aggDataP.YEAR = :Year
    AND aggDataP.STAT_TYPE_ID = (SELECT stat_type_id FROM
    stat_type WHERE stat_type = 'PRD')
    The above query returns only the geographic units that have capacity and production figures.
    I want to return all other regions that have a plantypeid regardless of whether they have capacity and production data.
    I tried to use outer joins but this has not worked. The database is an oracledatabase
    the below query returns all the geographic regions I need
    SELECT gu.GEOGRAPHIC_UNIT_ID, gu.GEOGRAPHIC_UNIT_DESC
    FROM GEOGRAPHIC_UNIT_RELATIONSHIP gur, GEOGRAPHIC_UNIT gu
    where
    gur.PARENT_GEOGRAPHIC_UNIT_ID = :geographicUnitId
    AND gur.CHILD_GEOGRAPHIC_UNIT_ID = gu.GEOGRAPHIC_UNIT_ID
    ANy idea how I merge the 2 queries?

    UNION

  • Need help in joins in OBIEE 10G

    Hi All,
    I have 2 tables like following.
    Table 1: Team
    Id| Team Name| Resource id
    1 | xxx | 1
    2 | yyy | 1
    3 | zzz | 1
    4 | xxx | 2
    Table 2: Resource Rate
    RSRC ID| Resource Name| Rate | Month | year
    1 | John | 10 | Jan | 2012
    2 | Max | 5 | Jan | 2012
    I have joined these 2 tables with Resource ID. I have a prompt with Team Name and Resource Name and I have a OBIEE chart report (Month,Year Vs Rate), in which if do not select team name in prompt or select only one team name then the results are fine but when i select 2 team names in the prompt for example 'xxx','yyy' the results gets doubled. If I select 3 team names, the result will be rate*3. But I want the result to be same value even after I select more than one team name.
    How to archive this??? Kindly help
    Edited by: GJ on Sep 10, 2012 10:39 PM
    Edited by: GJ on Sep 10, 2012 11:53 PM

    Hi Veeravalli,
    No I cannot have team name after resource name, because the purpose is to see based on team and then on resource. Moreover their is nothing wrong with queries generated, it is working as it is expected, Since the resource is mapped to 2 teams, I am getting duplicate values.
    I am just trying to find if there is a way to return always unique values.

  • Help with joins

    Hi,
    I am not sure if I am doing something wrong here, but would appreciate if someone point out my mistake.
    I have two table item and item_status
    item_status do not contain all the items but only the ones which have specific status
    Question(1):
    select count(*) from item
    and
    select count(*) from item left join item_status on item.itemid = item_status.item_id
    Result of these two queries dont match. Can you'll plz help me understand it.
    Question(2):
    I want count of items from table item by location (location is another field in table item) but I want to exclude items which have status lost in the item_status table.
    This is the query I used:
    select location, count(*) from item left join item_status on item.itemid = item_status.item_id where item_status.status = 'lost'
    is this the correct way, coz when I tried the figures where way to low,
    Thanks,
    Raja

    Hi, Raja,
    Raja Gopalan wrote:
    Hi,
    I am not sure if I am doing something wrong here, but would appreciate if someone point out my mistake.
    I have two table item and item_status
    item_status do not contain all the items but only the ones which have specific status
    Question(1):
    select count(*) from item
    and
    select count(*) from item left join item_status on item.itemid = item_status.item_id
    Result of these two queries dont match. Can you'll plz help me understand it.If there can be many rows in item_status that all match the same row in item, then the 2nd query will have a higher COUNT than the first.
    If you'd post your tables, I could show you in detail.
    Since you didn't I'll use tables from the scott schema.
    SELECT  d.deptno
    FROM     scott.dept     d;produces 4 rows:
    .   DEPTNO
            10
            20
            30
            40Only 3 of these rows have a match in the mep table, but the ones that match have many matches.
    SELECT     d.deptno
    ,     e.ename
    FROM          scott.dept     d
    LEFT OUTER JOIN     scott.emp     e     ON     d.deptno     = e.deptno;produces 15 rows
    .   DEPTNO ENAME
            20 SMITH
            30 ALLEN
            30 WARD
            20 JONES
            30 MARTIN
            30 BLAKE
            10 CLARK
            20 SCOTT
            10 KING
            30 TURNER
            20 ADAMS
            30 JAMES
            20 FORD
            10 MILLER
            401 row for each row in emp that has a match in dept (that is all 14 rows in emp) plus 1 row for every row in dept that does not have a match in emp (1 row).
    Question(2):
    I want count of items from table item by location (location is another field in table item) but I want to exclude items which have status lost in the item_status table.
    This is the query I used:
    select location, count(*) from item left join item_status on item.itemid = item_status.item_id where item_status.status = 'lost'
    is this the correct way, coz when I tried the figures where way to low,If you want a count by location, then you should say "GROUP BY location".
    You probably need a sub-query to check for 'lost'. Without seeing your tables and data, I can't be sure.
    Maybe something like
    SELECT  location
    ,     COUNT (*)
    FROM     item
    WHERE     itemid     NOT IN     (     -- Begin subquery to find bad item_ids
                       SELECT  item_id
                   FROM     item_status
                   WHERE     status     = 'lost'
                       )     -- End subquery to find bad item_ids
    GROUP BY  location
    ;

  • Joining these two queries

    I have two queries. The First one is long but very simple. All it has is long list of columns.
    First one:
    SELECT CL.CLIENT_ID, CA.CASE_ID, to_char(SYSDATE,'RRMMDD'),
    CL.MASTER_CLIENT_ID,
    CL.NAME1,
    nvl(CL.NAME2,' '),
    nvl(CL.ADDRESS1,' '),
    nvl(CL.ADDRESS2,' '),
    CL.POCO_POSTAL_CODE, nvl(CL.CITY,' '),
    nvl(CL.AUTO_SURV_CODE,0),
    CA.Col_Collector_Id
    FROM CLIENT CL, CASES CA
    WHERE CA.CL_CLIENT_ID = CL.CLIENT_ID AND
    CA.CASE_ID = :current_case_id
    Second one:
    SQL SELECT nvl(REF_NO,' '), nvl(to_char(DATE_OF_JUDGEMENT,'rrmmdd'),' ')
    FROM CASE_INSTANCES
    WHERE IN_INSTANCE_TYPE IN (1,8) AND
    CA_CASE_ID = :current_case_id AND
    PETITION_DATE = (SELECT max(PETITION_DATE)
    FROM CASE_INSTANCES
    WHERE IN_INSTANCE_TYPE IN (1,8)
    AND CA_CASE_ID = :current_case_id
    AND ROWNUM < 2 );
    The :current_case_id is passed as a parameter. The table in the second query i.e. CASE_INSTANCES is related to the first query with the CA_CASE_ID. Not all records fetched by the first query have a record in the second query. So you might have to use a LEFT JOIN or something. trying to join these two has worn me out. Please help me out someone.

    Hi,
    Simplified Solution:
    SELECT * FROM (
                        SELECT CL.CLIENT_ID, CA.CASE_ID, TO_CHAR(SYSDATE,'RRMMDD'),
                        CL.MASTER_CLIENT_ID,
                        CL.NAME1,
                        NVL(CL.NAME2,' '),
                        NVL(CL.ADDRESS1,' '),
                        NVL(CL.ADDRESS2,' '),
                        CL.POCO_POSTAL_CODE, NVL(CL.CITY,' '),
                        NVL(CL.AUTO_SURV_CODE,0),
                        CA.Col_Collector_Id
                        FROM CLIENT CL, CASES CA
                        WHERE CA.CL_CLIENT_ID = CL.CLIENT_ID ) a,
                        (SELECT NVL(REF_NO,' '), NVL(TO_CHAR(DATE_OF_JUDGEMENT,'rrmmdd'),' '),CA_CASE_ID
                             FROM CASE_INSTANCES
                             WHERE IN_INSTANCE_TYPE IN (1,8) AND
                             CA_CASE_ID = :current_case_id AND
                             PETITION_DATE = (SELECT MAX(PETITION_DATE)
                                                      FROM CASE_INSTANCES
                                                      WHERE IN_INSTANCE_TYPE IN (1,8)
                                                      AND CA_CASE_ID = :current_case_id
                                                      AND ROWNUM < 2
                        ) b
    WHERE a.case_id = b.ca_case_id(+)
    Regards
    K.Rajkumar

  • Help on joins

    Hi,
    In abap , how many types of joins are there.
    Like join, inner join, outer join etc..
    What do they mean.. and when to use them. Which is most efficient?

    Really there are two types,  inner join and left outter join.  Inner join is when you know that there is a 1.1 or 1.n link between the tables.  Here you will only get a hit if there is a link in the two tables. When it is not known whether there is a match in the second table, then here is where the left outer join comes in.  It will still give you the values from the first table, even though it might not find a match in the second table, the fields from the second table will simply be blank. Which is most efficient is not really a question here as they provide two separate functionalities.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21ec77446011d189700000e8322d00/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm
    Regards,
    RIch Heilman

Maybe you are looking for

  • Embedding DSL in Java

    Hello everybody, I have developed a DSL. Now I want to embed this DSL in java. I am new in this concept (Embedding DSL in GPL or java). Is it possible? Can I write the code between java codes with my DSL keywords? Best regards Parisa

  • SSAS DAX formula for same period last year not same month last year

    The DAX function sameperiodlastyear, only works if the period we are interested in, is the same as a month. However our Period 3 for 2014 was 05-march to 04-April and Period 3 in 2013 was 01-March to 31-March I have a dim_Date table with a separate Y

  • Downloaded Reader 10.1.3, PDFs won't open in Firefox

    Hello, I just downloaded Adobe Reader 10.1.3 - installation was successful. Now, when I try to open PDFs in Firefox, instead of opening up in the browser like they've done before, I'm just getting a blank page.  Before I installed the new reader, PDF

  • OUTBOUND IDOC

    hI aLL! I am doing an outbound interface with custom FM and assigned it to message type.Also i am using a extended IDoc for this.When i go to we19 and trigger my Idoc by clicking start outbound processing i am getting an error "port " does not exist

  • Trnasfered plant from Ecc to APO, but location not found

    Transfered plant from Ecc to APO, but the location is not available in APO Master data