Count distinct  from a master table and sum from a detail

Hello to all,
I have  a query like as:
         select a,b,c,     SUM(fa.ip1) S1, SUM(fa.ip2)   S2
         FROM tab1 FI, tab2 FA
         where fi.x1 = fa.x1
         and fi.x2 = fa.x2
         group by    a,b,c;
tab1's table is master table for tab2's table (one tab1 records there are   many tab2 records), (one to many relation)
My question is, how can I get to sum of columns: ip1 and ip2 from tab2 Fa, with only count(how many) of rows of tab1? 
Somethings similar to;
Select a,b,c, count(distinct fi.x1, fi.x2 ) nrec_of_FI,   SUM(fa.ip1)S1, SUM(fa.ip2)   S2
Thanks in advance

Sorry, I can't tell what you want just by looking at code that does not do it.
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that 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, with specific examples.
Always say which version of Oracle you're using (for example,
See the forum FAQ:
Perhaps you want to get the totals in 2 stages, like this:
WITH  five_column_totals  AS
    select    a, b, c
    ,         fi.x1, fi.x2       -- For debugging only
    ,         SUM (fa.ip1)   AS prelim_S1
    ,         SUM (fa.ip2)   AS prelim_S2
    FROM      tab1 FI
    ,         tab2 FA
    where     fi.x1 = fa.x1
    and       fi.x2 = fa.x2
    group by  a, b, c
    ,         f1.x1, f2.x2
SELECT    a, b, c
,         COUNT (*)             AS nrec_of_f1
,         SUM (prelim_s1)       AS s1
,         SUM (prelim_s2)       AS s2
FROM      five_column_totals
GROUP BY  a, b, c
Notice that the sub-query called five_column_totals is essentially what you posted, except that there fi.x1 and fi.x2 are included in the GROUP BY clause.  That means the sub-query will hve a separate row for each distinct combination of x1 and x2, which you can COUNT in the main query, GROUPing only BY a, b and c.

Similar Messages

  • How to find out master tables and concern child tables

    my schema contains 219 tables. I got this result by using query "selct count(*) from user_tables".
    Now i need to know about master tables and concern child tables from these 219 tables.
    please guide me.
    Thanks and Regards,

    What about this one!!!
    select a.owner,a.table_name,a.column_name,
         '------------------>' as POINTS_TO,b.owner,b.table_name,b.column_name
    from dba_constraints c
         join dba_cons_columns a on ( c.constraint_name = a.constraint_name and c.owner = a.owner)
         join dba_cons_columns b on ( c.r_constraint_name = b.constraint_name and c.r_owner = b.owner)
    where  (a.table_name = '&table' and (a.owner='&owner'))  -- foreign key
    --     and (b.table_name = '&table' and (b.owner='&owner') )  -- source key
         and ( c.constraint_type='R' )
    order by a.table_namecomment and uncomment one between theese two lines to choose the direction.
         (a.table_name = '&table' and (a.owner='&owner'))  -- foreign key
    --     and (b.table_name = '&table' and (b.owner='&owner') )  -- source keyBye Alessandro
    Edited by: Alessandro Rossi on 22-ott-2008 10.40

  • How do I pull information from a master table to another table?

    This may be quite simple, but I'm missing something.  I want to pull information from my master table into a secondary table.  In the Master Table in Column A, I have a list of teams ("Team 1" through "Team 12"), then in Columns B through D I have information for each assignment given to each team.  I want to have a secondary table for each team that lists all of their assignments.  So, this is what I want:   if Column A says 'Team 1', then I want the secondary table to have the info from Columns B through D.
    Again, I'm sure it's simple, but I just can't figure it out.
    Thanks for any help.

    Hi Mark,
    1)  But does this work if in the Master Table (which will be over 300 rows long) each team will show up 10-15 times over the course of the 300 rows randomly (hence the need to have sub-tables for each it's easier for them to see what their tasks are).
    Your fellow Numbers enthusiasts in this forum will need more information to help you with that. You are on the right track though with the idea of many tables. Therein lies the power of Numbers.
    2)  I'm a bit confused by the formula.  With the "$A2" do I select the first column in the Master Table?  And can you break down the second part of the formula?  The "$A$2:$D$4,2,0"  Why would you have A2 and D4 in the same formula?  They are not in the same row.  And what's the 2,0 at the end?
    Breaking this question down:
    With the "$A2" do I select the first column in the Master Table? 
    No. The $ keeps the reference to Column A absolute (it won't change to B then C as you Fill Right in the Team Task Table.
    And can you break down the second part of the formula?  The "$A$2:$D$4,2,0"  Why would you have A2 and D4 in the same formula?  They are not in the same row.
    $A$2:$D$4 is the range of cells (a rectangle) where VLOOKUP will search (in my example) but not in your 300 row table!
    And what's the 2,0 at the end?
    The syntax of VLOOKUP is VLOOKUP(search-for, columns-range, return-column, close-match)
    The 2,0 at the end means "return column" is 2 (the second column of the range) and 0 means "Exact Match" - it won't find a close match. After Fill Right you will need to edit the formula in each Column to change "return column" to 3, then 4, then ...
    With a table selected, click on the Function Button in the Toolbar and choose Function Browser. I find that much more useful than the Help Menu. However (there is always a however in life) the Help Menu will show Numbers User Guide, and Formulas and Functions Help. Download them and read at your leisure. The first four chapters of the User Guide are well worth a read. Use other chapters as a reference when you need them.

  • Creating a master table and using it to populate other tables.

    Hi everyone.
    I am a novice at using Numbers and I need some direction.
    I am looking to create a master table with information for our summer camp. This table will include vital information such as name, address, etc. along with cabin assignments, tuitions received, and more.
    We will separate this information into smaller tables that different portions of that master table for specific use. Such as: names and addresses for leaders, names and tuitions for registration, etc.
    My goal is to type the information into the master table and have it update the other tables automatically. Can someone direct me how to format the master and sub tables so that this is possible?
    I would greatly appreciate it and it will greatly reduce the record-keeping time for our camp.
    Thank You!

    Hi Roy,
    Welcome to the Numbers discussions. You are giving us a tall order, especially when we don't know your level of experience in programming spreadsheets.
    Here are a couple of basics to start the conversation...
    In normal spreadsheet programming, we Pull data from one location into another, we don't Push it or Send it. This should help you to understand that the hard work is done in the sub tables, not the master.
    You will use LOOKUP functions to pull the data to your sub tables. Download the Numbers User Guide and the Formulas and Functions User Guide and read up on them.
    In your master table, make sure you have one column that uniquely identifies each participant so it will be easy to reference that person in your sub tables.

  • Creating Tables From a Master Table?

    Hi all,
    I am trying to create tables that are generated from a master table. The reason behind this is I want to easily be able to modify this master table and then be able to print a well laid out invoice without all the extraneous information. I'm not really explaining this well so here is an example.
    My Master Table is on it's own sheet and has a categorized listing of products like so:
    Bananas, 5 units, $1.00
    Apples, 3 units, $0.50
    Peaches, 0 units, $2.00
    Bread, 0 units, $1.00
    Oatmeal, 0 units, $2.00
    Lettuce, 4 units, $2.00
    Celery, 6 units, $1.50
    Carrots, 2 units, $3.50
    On a seperate invoice sheet I would have multiple tables laid out to print. It will have a summary table like this:
    Fruit, Subtotal $6.50
    Vegetables, Subtotal $24.00
    Total $30.50
    and seperate tables for each category:
    Bananas, 5 units, $1.00
    Apples, 3 units, $0.50
    Subtotal $6.50
    Lettuce, 4 units, $2.00
    Celery, 6 units, $1.50
    Carrots, 2 units, $3.50
    Subtotal $24.00
    Notice it does not include the peaches or grains since I didn't actually sell any units of those.
    Is this possible? Can anyone point me in the right direction? Thanks.

    Most of this looks possible. The most obvious exception is not showing the separate table for grains when no grains are shown.
    A table has a defined number of rows and columns. That number may be changed manually, but I know no way of either adding or removing rows (or columns) through the use of formulas. If you want to use separate tables for each of these, you will need to set up four separate tables, each with the number of columns needed and, assuming there is a possibility that any particular order may include all items in at least one category, each with as many rows as there are items in the category for that table.
    If you are willing to forego separate tables on the Invoice, then an outcome similar to what you ask is likely possible.
    In your example, you have listed the subtotals for each category in which there has been an order at the top of the page, then have repeated those subtotals in a second line in each separate table. Why?

  • How to load master data and hierarchies from R/3 systems

    HI all,
    how to load master data and hierarchies from R/3 systems.
    Please explain the steps.

    Its normally done following: Transferring the master datasources in RSA5 to RSA6 and then replicating the DS into BW and assignment of DS to Infosource and cretaion of Infopackage and load it into the master tables.
    Generally, the control parameters for data transfer from a source system are maintained in extractor
    customizing. In extractor customizing, you can access the corresponding source system in the source
    system tree of the SAP BW Administrator Workbench by using the context menu.
    To display or change the settings for data transfer at source system level, choose Business
    Information Warehouse → General Settings → Maintaining Control Parameters for Data Transfer.
    Note: The values for the data transfer are not hard limitations. It depends on the DataSource if these
    limits can be followed.
    In the SAP BW Scheduler, you can determine the control parameters for data transfer for individual
    DataSources. You can determine the size of the data packet, the number of parallel processes for
    data transfer and the frequency with which the status IDocs are sent, for every possible update
    method for a DataSource.
    To do so, choose Scheduler → DataSource → Default Settings for Data transfer.
    In this way you can, for example, update transaction data in larger data packets in the PSA. If you
    want to update master data in dialog mode, smaller packets ensure faster processing.
    Hope this info helps.

  • Can we hide the tables and columns from subject areas in the front end

    Is there any way to hide the tables and columns from the subject area in front end.I need to create a report with some tables which the user does not want to see.So after creating the reprot can I hide those tables and columns in the front end

    Your question is not that clear to you want to hide the entire table/column that dont want to show up in the front end then you could do in Presneation Layer in the RPD by going Permissions in the property of that object.
    But if you want to hide the column in the report that can be visible in the subject Area: go to column properties -> Column fomat...thereis Hide option.
    Can you please elaborate your question...what exactly you are looking for...

  • BPC 7.5 NW: Import master data and Hierarchy from BI

    There is a HTG about Import master data and Hierarchy from SAP NT BW, the BPC cost center master data's property have corresponding attribute  InfoObject 0COSTCENTER of BW.
    what about for those properties which do not have corresponding attribute in BW? I would asume that START_ROUTINE and END_ROUTINE will do this in BPC side,  can we also do this on BW side instead of BPC side?

    You can check this in start routine which can be called from Transformation file using BADI.
    Hope this helps...

  • Using Bulk operations for INSERT into destination table and delete from src

    Is there any way to expediate the process of data movement?
    I have a source set of tables (with its pk-fk relations) and a destination set of tables.
    Currently my code as of now, is pickin up the single record in cursor from the parentmost table, and then moving the data from other respecitve tables. But this is happening one by one... Is there any way I can make this take less time?
    If I use bulk insert and collections, i will not be able to use the DELETE in the same block for same source record.

    I'm not 100% sure how your code flows from what you've stated, but generally you should try and avoid cursor FOR LOOPS and possibly BULK COLLECTING.
    I always follow the sequence in terms of design:
    1. Attempt to use bulk INSERTS, UPDATES and/or DELETES first and foremost. (include MERGE as well!)
    2. If one cannot possibly do the above then USE BULK COLLECTIONS using a combination of RETURNING INTO's and
    However, before you follow this method and if you relatively new to Oracle PL/SQL,
    share the reason you cannot follow the first method on this forum, and you're bound to find some
    help with sticking to method one!
    3. If method two is impossible, and there would have to be a seriously good reason for this, then follow the cursor FOR LOOP
    You can combine BULK COLLECTS with UPDATES and DELETES, but not with INSERTS
    bulk collect into after insert ?
    Another simple example of BULK COLLECTING
    Re: Reading multiple table type objects returned

  • Export tables and records from oracle 8i to oracle 10g

    i had installed oracle 10g, but i want to export my tables and record from oracle 8i to oracle 10g.
    can you tell me

    Please have a look to Using Different Releases and Versions of Export in Utilities document.

  • How to join  fields from different internal tables and display into one int

    hai i have one doubt...
    how to join  fields from different internal tables and display into one internal table..
    if anybody know the ans for this qus tell me......

    you can read data as per condition and then can join in one internal table using READ and APPEND statement..refer to following code.
    SELECT bwkey                         " Valuation Area
             bukrs                         " Company Code
        FROM t001k
        INTO TABLE i_t001k
       WHERE bukrs IN s_bukrs.
      IF sy-subrc EQ 0.
        SELECT bwkey                       " Valuation Area
               werks                       " Plant
          FROM t001w
          INTO TABLE i_t001w
           FOR ALL ENTRIES IN i_t001k
         WHERE bwkey = i_t001k-bwkey
           AND werks IN s_werks.
        IF sy-subrc EQ 0.
          LOOP AT i_output INTO wa_output.
            READ TABLE i_t001w INTO wa_t001w WITH KEY werks = wa_output-werks.
            READ TABLE i_t001k INTO wa_t001k WITH KEY bwkey = wa_t001w-bwkey.
            wa_output-bukrs = wa_t001k-bukrs.
            MODIFY i_output FROM wa_output.
            CLEAR wa_output.
          ENDLOOP.                         " LOOP AT i_output
        ENDIF.                             " IF sy-subrc EQ 0

  • Copy all tables and data from remote schema to local schema

    I am using Oracle 10g Enterprise edition as a database and Windows 7 as the operating system.
    My Requirement is to copy all the tables and data from remote machine database to my local machine.
    I created a DB link between my location schema and remote machine schema. Database link created successful. Error what i am getting when i am trying to import all the tables from the remote data is as mentioned below
    I created a directory gave all the privilege to do read and write on the directory.
    Directory name : DUMP
    Remote Schema name / Password : portal / m3892!2
    When i run this scrip from command prompt
    It is giving me following error please suggest me what is the mistake i couldn't trace
    ORA-31631: privileges are required
    ORA-39149: cannot link privileged user to non-privileged user

    Thanks I gave the grant permission for the "portal" remote user. I didn't not get the error. Issue am facing now is I need to copy the entire schema of production to my local system production.
    I am currently using the below script to copy. it not working. what might be the reason there is no error message coming but still i don't see any tables in my local system after executing this script
    Or suggest me some other script to copy all the tables and procedure function from remote database to my local database using impdp script

  • Deletion of data from change log table and PSA

    For a DSO  I want to delete data from "Chnage log table"  and " PSA Tabel".
    For the DSO manage screen I have seen " Environment-> " Delete changelog table" from this we can delete chnage log table data as per my understanding.
    at PSA Level Mange screen also I have seen " Environment-> " Delete changelog table" from this option also it deletes the data from change log table or it deletes data from PSA table?.
    if this option also deletes data from changelog table then how we can delete data from PSA table?
    Please clarify me

      I am not sure what are you referring to from your point "PSA Level Mange screen also I have seen " Environment-> " Delete changelog table". When ever you click on manage for your psa you will be routed to a popup where you can see all your requests in the PSA table & there after if you click on any single request you will get Environment menu option but there wotn be any change log deletion option available. Please check again? Right clicking on your data source will take you to the manage requests for PSA. You can selectively delete the requests as required.
    For DSO when you right click on manage you can directly find Delete change log data option in the Environment tab. there you can select the requests you want to delete.
    Also if you want to automate the deletion process then you can simply create a chain and include the steps for PSA deletion & change Log deletion accordingly.
    Also it is recommended to keep on clearing the PSA table & Chage log data at regular intervals as it saves the disk space & thus helping in performance optimization
    Please refer the below doc at SDN, it will be helpful for you in automating the process of change log deletion & PSA deletion.
    Hope it clears your doubts

  • Clean install on new 1TB hdd, Yosemite keeps freezing when copying data from an ext drive and also from a usb

    Hi all,
    I'm trying to figure out why my macbook keeps freezing when I try to drag my data across to it (even small files from a USB).
    I've had to force restart over a dozen times today :/
    I ran EtreCheck and there are a couple of issues (I've no idea what they mean).
    If anybody could share some light into the report below I would be very grateful:
    Problem description:
    Macbook Pro mid 2010, Yosemite, blank new install on 1 TB hdd, keeps freezing when copying data from an ext drive and also from a usb
    EtreCheck version: 2.2 (132)
    Report generated 5/2/15, 4:55 PM
    Download EtreCheck from
    Click the [Click for support] links for help with non-Apple products.
    Click the [Click for details] links for more information about that line.
    Hardware Information: ℹ️
        MacBook Pro (13-inch, Mid 2010) (Technical Specifications)
        MacBook Pro - model: MacBookPro7,1
        1 2.4 GHz Intel Core 2 Duo CPU: 2-core
        8 GB RAM Upgradeable
            BANK 0/DIMM0
                4 GB DDR3 1067 MHz ok
            BANK 1/DIMM0
                4 GB DDR3 1067 MHz ok
        Bluetooth: Old - Handoff/Airdrop2 not supported
        Wireless:  en1: 802.11 a/b/g/n
        Battery: Health = Normal - Cycle count = 2061 - SN = W013358KQD3BA
    Video Information: ℹ️
        NVIDIA GeForce 320M - VRAM: 256 MB
            Color LCD 1280 x 800
    System Software: ℹ️
        OS X 10.10.3 (14D136) - Time since boot: 0:7:25
    Disk Information: ℹ️
        ST1000LM024 HN-M101MBB disk0 : (1 TB)
            EFI (disk0s1) <not mounted> : 210 MB
            Macintosh HD (disk0s2) / : 999.35 GB (968.00 GB free)
            Recovery HD (disk0s3) <not mounted>  [Recovery]: 650 MB
        HL-DT-ST DVDRW  GS23N 
    USB Information: ℹ️
        Apple Inc. Built-in iSight
        Apple Internal Memory Card Reader
        Apple Inc. BRCM2046 Hub
            Apple Inc. Bluetooth USB Host Controller
        Apple Computer, Inc. IR Receiver
        Apple Inc. Apple Internal Keyboard / Trackpad
    Gatekeeper: ℹ️
        Mac App Store and identified developers
    Problem System Launch Daemons: ℹ️
    Launch Daemons: ℹ️
    User Launch Agents: ℹ️
        [failed][...] [Click for details]
        [loaded] [Click for support]
    User Login Items: ℹ️
        iTunesHelper    UNKNOWN Hidden (missing value)
        Caffeine    Application  (/Applications/
    Internet Plug-ins: ℹ️
        Default Browser: Version: 600 - SDK 10.10
        QuickTime Plugin: Version: 7.7.3
    3rd Party Preference Panes: ℹ️
    Time Machine: ℹ️
        Time Machine not configured!
    Top Processes by CPU: ℹ️
            20%    WindowServer
             4%    Safari
             3%    hidd
             1%    launchd
    Top Processes by Memory: ℹ️
        1.07 GB
        439 MB    kernel_task
        90 MB    spindump
        57 MB    mdworker(5)
        57 MB    Safari
    Virtual Memory Information: ℹ️
        4.54 GB    Free RAM
        3.46 GB    Used RAM
        0 B    Swap Used
    Diagnostics Information: ℹ️
        May 2, 2015, 04:47:31 PM    Self test - passed
        May 2, 2015, 01:39:52 PM    /Library/Logs/DiagnosticReports/DesktopServicesHelper_2015-05-02-133952_[redact ed].cpu_resource.diag [Click for details]
        May 2, 2015, 01:23:20 PM    /Library/Logs/DiagnosticReports/ _[redacted].crash

    Thanks - I had a 1TB hdd in my macbook for about 12 months but it started playing up a few days ago (I got the question mark folder on bootup) so I bought another 1TB hdd (same model) and started from scratch.
    My macbook is an early 2010... now I'm wondering if Yosemite is a bit too much for it?
    The ext hdd is my timemachine backup, so yes I have used it often and it has my TM backups - and the usb is a new usb which Ive used a few times.
    The issue seems to be when Im transferring files from an ext drive to my mac. I can use it fine and browse (worked find for 45 mins) then I tried to bring my data across.. and it copied a few gig over before total freeze.
    This has happened about a dozen times.
    I keep running disk utility and checking the disk. I also just ran the apple diagnostics tool that came in the apps cd - the hardware apears to be fine.
    I have a 250 gb partition for the OS and the rest is my second partition for data.
    I'm now wondering if I should reformat the first partition, install leopard from the CD, then upgrade to mavericks and leave it at that.
    Any thoughts would be awesome. Thank you for reading and replying!

  • Table and fields for tax details

    I have to create one Finance module Report in which i want to display net amount without tax for one single line item which is open item for incoming customer invoice, the accounting department need to know the net value (without tax) .
    In tcode FB03 , if you see the document number then it will give all accounts(customer), posting key wise amount, but this amount is gross amount. in this amount tax amount is added as per tax code. (you can see by clicking tax details tab), and tax calculated is for whole ducoments number not for single line item.
    i want net amount without adding tax amount for particular single line item. so please guide me table and fields from where and how i can calculate. in tax tab there is field base amount but its giving calculation against all total against document.
    table i am using in my report is KNA1.KNKK, KNB1, BKPF. BSEG.
    Give me some idea. how can i prepare report.
    Have a Nice Day,

    Dear Dzed Maroz ,
    Thanks for your reply.
    I have already checked these fields (HWSTE, FWSTE) in table BSET. this fields tax amount againt that Document Number. (which may contains more than one line items), but my requirement is to find the amount without tax for individual line item.
    reason is , i want to display in my report only open items and it will be a line item, so i am displaying net amount as well base amount (without tax) for particular line items.
    but tax details is calculated based on document number not against customer number.this is incoming invoice
    ,and in customization tax code is assigned, so its reflecting amount after including tax amount.
    is there any way to find out solution? please give me some idea.

Maybe you are looking for

  • Calling from the application Slow vs. Running through SQL developer Fast

    Alright, we write many applications that make use of calling stored procedures in packages to return data. This is the only time i have ever encountered this issue and have not been able to pinpoint the cause. This application is very data-centric an

  • ABAP Editor not allowing me to input the code..

    Hi Gurus, I am trying to enhance my datasource, but whenever i type cmod and enter the ABAP editor screen, i can not type anything, even though i am in change mode....the screen is with white background and i can not type at all....please help with m

  • Ink levels no longer viewable

    The ink levels are no longer viewable since I installed windows 7.  Any help  Thanks

  • RG23C regarding

    when i post rg23c (part-II) entry posting in J1IEX is ex.base : 15000  [tax code: Excise Duty 8.24%+vat4%] cenvat on hold:2472 cr RG23C BED : 2400 cr ECS:48 cr SHEC:24 cr cenvat clearing:4944 dr in the duty values tab: for total duty it is showing be

  • Undo delete message command in Mail Exchange account doesn't work post Yosemite

    Before I installed Yosemite on my MacBook Air, I was able to undo a message deleted in Mail Exchange 2010 account with menu command (Undo Delete Message) or Command-Z.  Even with recent updates to 10.10.1 which were supposed to address Mail-Exchange