compare amounts of two separate tables to each other.

I have two tables
 table pants

id amt
1 50
1 50
1 50


table jacket

id amt
1  50
1  50
1  50

when i do a select  of say 


SELECT  a.id, b.id   SUM(a.amt),sum(b.amt) from pants a, jacket b WHERE A.ID = B.ID group by a.id, b.id 


/* i get a really awkaward result i can't understand what im doing wrong*/
I would get a single line with the result set


an a.mt b b.amt
1 1 150 150


but instead my amount in duplicate like 3 or four times. like the 450 and 450?
I tried to use SEPARATE on the sql, but I got no where can someone throw me a BONE here.
Thanks in advance.

That's what you want...

sudhakar@ORCL>-- Sample data in virtual tables
sudhakar@ORCL>with pants as
  2  (select 1 id, 50 amt from dual union all
  3  select 1 id, 50 amt from dual union all
  4  select 1 id, 50 amt from dual)
  5  ,jacket as
  6  (select 1 id, 50 amt from dual union all
  7  select 1 id, 50 amt from dual union all
  8  select 1 id, 50 amt from dual)
  9  -- Actual QUERY
 10  select aid, bid, aamt, bamt
 11  from
 12  (SELECT  a.id aid,   SUM(a.amt) aamt from pants a group by a.id) pants_summary
 13  inner join
 14  (SELECT  b.id bid,   sum(b.amt) bamt from  jacket b group by  b.id ) jacket_summary
 15   on( pants_summary.aid = jacket_summary.bid)
 16   ;

       AID        BID       AAMT       BAMT
---------- ---------- ---------- ----------
         1          1        150        150

sudhakar@ORCL>

pre
Sudhakar B.

Tags: Database

Similar Questions

  • problem of query by comparing records from the same table against each other

    Hi, i'ms truggling to see where I am going wrong here. I have data from cards of following music: -.
    with charts_table as (select 1 id,'oasis' product_name,0801 week, 20 week_chart_position, 20 highest_chart_position from dual
    union select 2,'oasis',0802,14,14 from dual
    union select 3,'oasis',0803,17,14 from dual
    union select 4,'oasis',0804,29,14 from dual
    union select 5,'kings of leon',0801,55,55 from dual
    union select 6,'kings of leon',0802,22,22 from dual
    union select 7,'kings of leon',0803,35,22 from dual
    union select 8,'kings of leon',0804 , 11 , 11  from dual
    union select 9,'bob dylan',0801, 88 , 88  from dual
    union select 10,'bob dylan',0802,79 , 79  from dual
    union select 11,'bob dylan',0803,54,54 from dual
    union select 12,'bob dylan',0804,22,22 from dual
    union select 13,'kid rock',0801,19,19 from dual
    union select 14,'kid rock',0802,24,19 from dual
    union select 15,'kid rock',0803,55,0 from dual
    union select 16,'kid rock',0804,44,0 from dual)
    italic , I need to identify the rogue data where the highest_position is incorrectly registered lower or 0 as there
    position of the highest week was at an earlier date. (stick with me) for example in this kid of rock data initially charted at position 19. What follows
    week (0802) his week_chart_position slipped to 24 and the position the highest card is correctly saved at 19 (ie the week 1). The problem
    is available in week 0803 and 0804 when somehow the data was corrupted and the higest_chart_position is trying to read 0 (instead of 19). How can I write a query to identify this error?

    is the best I have at the moment:-
    select * from charts_table ct1 where 
    nvl2(highest_chart_position,0,99999)>
    (select min(week_chart_position) from charts_table ct2
    where ct2.week<ct1.week
    and ct1.product_name=ct2.product_name)
    but it's not working. can someone help and tell where I'm wrong. Thanks a lot for the research/resolve.

    Ahh, I was suggesting using the lag function to ensure that highest chart position is not fall lower than highest prior chart positions. Your concern is he reports a higher chart position that she never had. In this case I use the MIN function as an analytic function rather than as an aggregate function:

    with t1 as (
      select ct.*
           , min(week_chart_position) over( PARTITION by product_name order by week) highest
        from charts_table ct
       order by product_name, week
    )
    select * from t1 where highest != highest_chart_position;
    

    Conversely, you place your order of cards, which is the highest rank is 1, thew me. I saw the high word and the expected value in the highest chartposition column to be on the rise, but has seen examples of it decreases. It was an oversight on my part.

    Published by: Sentinel on October 9, 2008 08:31

  • Remove the same instance of two separate tables online

    Hi all

    I have two tables that each repeatable lines. Both tables must display almost the same information in each case of the line (I managed to code to link the values in specific cases of the lines). However, I added a button in the repeatable row, which allows the user to remove from the current instance of the line, so will they look back and realize that they do not need a line, they can take directly from the table. However, I can't seem to get the deletion affects the same instance of row of the second table. Is it possible to do this? I'm not terribly familiar with the instance Manager.

    Any help would be greatly appreciated. I just can't understand how to identify a specific instance of the repeatable row in table 2.

    Hello

    Removing instances in the event of an object that is inside the instance, you must ensure that you remove this particular instance at the end of the event.

    For example:

    If you delete the instance that the button is on the inside before finishing the entire event, the program will not recognize what event is to finish because you have removed it from the object that is triggered...

    You try here at the end of the code that no longer exists...

    I suggest that you still need to delete the instance (this) object at the end of any event to make sure to complete all your actions before deleting the object.

    I hope this helps!

  • Two sessions are locked each other in

    Hi all

    My database is Exadata machine. 11.2
    These days, we met a case, it's two sessions is always blocked by the other. I get this info from v$ session blocking_session.
    For examle, the information looks like

    event blocking_session sid
    1 locking cache libarary 2
    2 lock hiding 1 row

    and as you know there are a lot of other sessions are blocked by sid 1.

    In lookiing upwards of v$ sql, I got the SQL for these 2 sessions.

    / * QSMQ VALIDATION * / ALTER SUMMARY 'XXXXX '. "" Gxxx_CP_CAL_TIME_TEMP_MV "COMPILATION

    / * QSMQ VALIDATION * / ALTER SUMMARY 'XXXXX '. "" Gxxx_CP_CAL_TIME_MV "COMPILATION

    Two of these MV 2 share some underlying objects. And both of the 2 sessions began at around the same time.
    If the compilation must face the lock on the object, why the 2 sessions block each other?

    Can someone give me some advice, please?

    Best regards
    Leon

    event blocking_session sid
    1 locking cache libarary 2
    2 lock hiding 1 row

    These aren't waiting for line lock (TX Enqueue waits). These are expectations about the dictionary cache - for example to prevent the DDL (ALTER, COMPILE, CREATE etc.) running while DML is still ongoing. This ensures that dependencies are maintained.

    (if you have a transaction that retrieves 4 columns in a table and another session adds or deletes a column, while the transaction is in progress? how oracle would ensure that the "structure" of the table remains consistent? the DOF is prevented and waits for a lock on the library cache).

    The cache line is the data dictionary cache.

    Hemant K Collette

  • two PID.vi effect each other or not in the same program?

    Hello!

    I know that the PID.vi can be used in a multi-channel manner, and controls of this case different PID do not distrube each other. What if I use the same loop PID.vi two s to control two independent processes? They will be the effect each other? I want them to work independently, how can I handle this?

    Thank you!

    If they are reentrant, each instance in the schema will work independently and is want you want. No changes are necessary.

    (Do not change system screws or things will break up with the next update of the software )

  • Emergency aid! How can I run in the same block diagram two separate labview codes each with a diferent execution timings?

    Dear all.

    I have 2 progrlams application in the same schema. the intention is to use the 2 different when excuting programs for different applications, and each have to stop and start button, of course, I'll have to stop master. But when I run the program, it works as a program in time, it's the 1st block which I make active only, when I tried to activate the second block, that won't work, works only when I stopped the1st one. So, he wants your help, how can I solve my problem. Here I am attaching some of my programs.

    Kind regards!

    Furthermore, if you want two loops to run at the same time, just this.

  • Pseudo-classes: how to apply the different link colors in two separate table cells

    How can I add the link for these two cells status styles?

    Foot table is in an include file

    The current code is:

    < table width = "800" border = "0" align = "center" cellpadding = "0" cellspacing = "0" >
    < b >
    < class td = "tdfooter1" > < a href = "index.php" > home < /a > |  < a href = "about.php" > about our company < /a > |  < a href = "clients.php" > customers < /a > |  < a href = "partners.php" > our partners < /a > |  < a href = "contact.php" > contact us < /a > < table >
    < /tr >
    < b >
    < class td = "tdfooter2" > data Copyright 2010 carpet & amp; Carpet |  < a href = "terms.php" > terms of use < /a > |  < a href = "privacy.php" > < /a > privacy statement < table >
    < /tr >
    < /table >

    Current CSS is:

    {.tdfooter1}
    do-family: Tahoma;
    do-size: 12px;
    color: #FFFFFF;
    background-color: #666666;
    text-align: center;
    height: 30px;
    }
    {.tdfooter2}
    do-family: Tahoma;
    do-size: 12px;
    background-color: #CCCCCC;
    text-align: center;
    text-transform: capitalize;
    height: 30px;
    }

    Lack of variations, and any help will be really appreciated

    .tdfooter1 a: link {...

    .tdfooter1 a: visited {...

    .tdfooter1 a: hover {...

    .tdfooter1 a: active {...

    .tdfooter2 a: link {...

    .tdfooter2 a: visited {...

    .tdfooter2 a: hover {...

    .tdfooter2 a: active {...

  • I have two iPhones (6 &amp; 7), with an Apple ID. Can I have two separate iCloud of each phone backups?

    My question is perhaps a bit 'wordy '. I have a phone work and personal telephone, so to put it simply, I would use an Apple ID to ensure all the contacts and emails remain aligned. The phones are not the same, for example, need a social media applications, etc., as where my work phone didn't. Is it possible to have both work and personal supported until an iCloud account? Or backup the latest will replace the last phone to save?

    Thanks for your help!

    You can have backups for your iPhone iPhone 6and 7.

    You will see separate backups in virtue:

    Settings > iCloud > storage > storage management.

    See "BACKUPS".

    Nick

  • Two signals interfering with each other

    Hello

    I have a problem with a trace of pressure and a vibration sensor. I have a card PCIe - 6341 DAQ. I connect my pressure signal to a channel (say ach0) and I connect the vibration to another analog channel (say ach7).

    In labview, I use an assistant DAQ. When I use it to sample only one of the signals, there is no problem. If I add two channels in the configuration dialog box, the signal pressure becomes superimposed vibration signal.

    Analog signals entering data show no interference (checked with an oscilloscope). I suspect that what is happening inside the data acquisition card.

    Any ideas why this happens?

    Thank you

    Masoud Mashkournia

    Hi Masoud,

    It seems that you see 'ghosts' on your channels.  The 6341 multiplex via the analog inputs.  Therefore, if you are scanning between high voltage and low voltage, especially when you use CSR, you can see ghost images if the signal from the previous channel file completely or have a path to the ground.  Here is a good article from the knowledge base that describes ways of eliminating this remanence.

    I noticed that you use the configuration of the CSR on your DAQ Configuration Wizard.  Try using a differential input configuration.  This can help eliminate unwanted common mode voltages.  In addition, you can try place a middle way in scanning which is connected to the ground at AIGND in the DAQ command scan.  This can help with the mass of the previous signal.  Most likely, you will want to scan in this order: pressure, ground, vibrations.

    Please let me know if it helps.

    Best,

  • How can I cut my two Gmail accounts with each other.

    Hello

    Whenever I connect to my Gmail account, I get the warning that there was a new sign from Firefox on Windows.

    I don't know why, but I get the same message on another Gmail account that I have not signed in to.

    In fact, on my mobile, I've set up these two Gmail accounts and I always switch between them.

    On my laptop, I always sign in to account by time, while on my laptop I am connected at the same time, all the time.

    How can I disconnect the two accounts, so that the e-mail, which belongs to the old, will not be sent to the latter, as well?

    I would like to disconnect them on my laptop and on my laptop.

    Thank you

    Francis UK

    Hello Francois,.

    Thank you for visiting Microsoft Community and we provide a detailed description of the issue.

    According to the description, I understand that you experience the problem when you try to connect to the Gmail account, you get the warning that there was a new GIS in Firefox on Windows. Now, you want to know how to disconnect the two accounts so that the e-mail which belongs to the former will not be sent to the latter.

    Certainly, I understand your concern and will try my best to help you.

    In order to get more help on this issue, you can post your query on the forum of Gmail. Please see the links below.

    https://productforums.Google.com/Forum/#! Forum/gmail

    https://support.Google.com/mail/?hl=en#topic=3394144

    I hope this information is useful.

    Please let us know if you need more help, we will be happy to help you.

    Thank you.

  • Merge two EncodedImages next to each other

    Hello

    I've been looking around on the forum and I wonder if you can have two EncodedImages, apply the GetData method at a time and combine it with an EncodedImage without using any Bitmap. I've seen different messages, but it is inclear for me.

            byte[] array2 = image1.getData(); 
    
            byte[] array1 = image2.getData();
            byte[] combined = new byte[array1.length + array2.length];
            for (int i = 0; i < combined.length; ++i)
            {
                combined[i] = i < array1.length ? array1[i] : array2[i - array1.length];
    
            }
            map = EncodedImage.createEncodedImage(combined, 0, combined.length);
    

    Do you need a complete resolution of this image? If you merge only to display resize your image source. If you need full resolution image that you will have to work on smaller pieces of the image source (scratches) and encode them on your own.

  • Two buttons reacting with each other

    Hello

    I have a page where I use icons in the middle and a downstairs main navigation bar. Both have the same links.

    I hope to somehow connect these two. So that when you rollover say icon 'products', the text of 'products' in the navigation bar would emphasize and so on...

    My buttons are just converted symbols, not actionscript used to do rather than stop.

    see you soon,

    Spawn

    Google is the best place to search for tutorials, but it's pretty simple so that you won't have a tutorial.

    you create a movieclip and frame 1, you attach a stop() to the framework and graphics 'up '.  create a 'more' (and if you want a 'low' setting).  If you graduate your frames in the obvious way you then use:

    {yourbutton.onRollOver = function ()}

    this.gotoAndStop ("over");

    }

    {yourbutton.onRollOut = function ()}

    this.gotoAndStop ("up");

    }

  • Two fonts keep intersecting each other?

    When I create buttons of menu on my master page and hyperlink them to different pages I get my policy that Montserrat is replaced by another, according to what is selected. If anyone has had this problem and if so is there a resolution?

    Thank you.

    Looks like you might have another policy applied to the active state. Carefully inspect all the States of the menu item as well as the label to the breast.

    Abhishek

  • How to divide a string into an array of strings in separate tables

    Greetings,

    I have an array of strings which displays strings in a text file. I read each line of the text file and put it in an element of the matrix of the chain.

    Now, I'm trying to divide each string for each part of the chain, then put in a separate table. Each element in the chain is separated by a comma. I hit a brick wall at this point and would like to help please?

    The purpose of this is so that I have 4 tables that will be ready their item values and set variables based on these values until I went through all the elements in each array.

    Attached example.

    Also my VI is attached.

    Thanks in advance for your help.

    Then just use Index Array on 2D array provided.

  • Need a better query... Join the indictments of two separate queries...

    Hi all

    I have two separate tables. Initially, I write separate queries to get the number of these tables... Now my requirement is to get the sum of the counts of two queries and I need to write to in a query of monkey...

    I wrote something like below... is there any query better than that...
    select count  as total from (select distinct site_code,cd_conv_to FROM AA.AAT_440_SVA_DETAIL A , AA.CONV_DETS B , GB.GBT_A02_SITE C WHERE A.PLANT_CODE=B.CD_CONV_FROM AND CD_CONV_TYPE='GSPSPLRG' AND A.SCODE=C.SCODE AND SCODE >= 'C' UNION ALL select distinct T_MANU,cd_conv_to  FROM AA.AAT_447_ISP_Q A , AA.CONV_DETS B , GBT.GBTSITE C WHERE STATUS='VAT' AND A.PCODE=B.CD_CONV AND CD_CONV='GSP' AND A.CD_DIRECT=C.SCODE AND CD_DIRECT >= 'C') q1
    Thank you
    ASP.

    Hello

    Try:

    SELECT NVL(ilv1.cnt1,0) cnt1, NVL(ilv2.cnt2, 0) cnt2, NVL(ilv1.cnt1, 0) + NVL(ilv2.cnt2,0) total_cnt
      FROM (
      SELECT COUNT(distinct site_code,cd_conv_to) cnt1
         FROM AA.AAT_440_SVA_DETAIL A , AA.CONV_DETS B , GB.GBT_A02_SITE C
      WHERE A.PLANT_CODE=B.CD_CONV_FROM
          AND CD_CONV_TYPE='GSPSPLRG'
          AND A.SCODE=C.SCODE AND SCODE >= 'C' ) ilv1,
      (SELECT COUNT(distinct T_MANU,cd_conv_to) cnt2
          FROM AA.AAT_447_ISP_Q A , AA.CONV_DETS B , GBT.GBTSITE C
       WHERE STATUS='VAT'
        AND A.PCODE=B.CD_CONV
        AND CD_CONV='GSP'
        AND A.CD_DIRECT=C.SCODE AND CD_DIRECT >= 'C') ilv2
    

Maybe you are looking for

  • Should I install this download: FirefoxPatch.exe received today?

    This download has appeared today and I downloaded but not installed what I fear that perhaps it is maleware. Instead, I refreashed FireFox. I've had several accidents on several web sites in the last few weeks so I try to install this patch, but then

  • How can I upgrade my browser

    I understand that the latest version of Mozilla firefox is 27. When I try to updatetells me I have the latest version 25.0.1 What is the correct version.

  • P7-1001 problems to use monitor 2560 x 1440

    I have HP P7-1001. AMD X 2 645 office, ATI 4200 integrated graphics. I tried to use the screen QHD LED by the Korea Crossover. It has a resolution of 2560 x 1440. These monitors are supposed to use the same boards as Apple Cinema. But using my deskto

  • What are the details of the 3-year warranty on Tecra?

    What are the details of the 3-year warranty for computer Tecra laptop w/r bad pixels? Toshiba gives no kind of guarantee of "zero pixel wrong" even for a limited period?

  • LabVIEW arduino uno bad data transfer

    Hello I have some problems with the transfer of data from the arduino uno to labview. I did a VI where I can control the power of a heater with measurements of temperature with arduino uno. The problem is that from time to time the incorrect temperat